blob: f74d2378088ccce375dbca7adfa221195928e7cc [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
Chen-Yu Tsaidd9c8642022-11-29 15:59:25 +080013#define INIT_DUMB_DRIVER_WITH_NAME(driver, _name) \
Anders Delliene5bef532020-06-10 10:30:44 +010014 const struct backend backend_##driver = { \
Chen-Yu Tsaidd9c8642022-11-29 15:59:25 +080015 .name = _name, \
Anders Delliene5bef532020-06-10 10:30:44 +010016 .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
Chen-Yu Tsaidd9c8642022-11-29 15:59:25 +080026#define INIT_DUMB_DRIVER(driver) INIT_DUMB_DRIVER_WITH_NAME(driver, #driver)
27
Anders Delliene5bef532020-06-10 10:30:44 +010028static const uint32_t scanout_render_formats[] = { DRM_FORMAT_ARGB8888, DRM_FORMAT_XRGB8888,
29 DRM_FORMAT_ABGR8888, DRM_FORMAT_XBGR8888,
Yiwei Zhang65d4bf32021-11-18 20:06:00 +000030 DRM_FORMAT_BGR888, DRM_FORMAT_RGB565 };
Anders Delliene5bef532020-06-10 10:30:44 +010031
Nicholas Bishop17d3eb82022-04-08 17:37:52 -040032static const uint32_t texture_only_formats[] = { DRM_FORMAT_R8, DRM_FORMAT_NV12, DRM_FORMAT_NV21,
Anders Delliene5bef532020-06-10 10:30:44 +010033 DRM_FORMAT_YVU420, DRM_FORMAT_YVU420_ANDROID };
34
35static 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
Nicholas Bishop17d3eb82022-04-08 17:37:52 -040043 drv_modify_combination(drv, DRM_FORMAT_R8, &LINEAR_METADATA,
44 BO_USE_HW_VIDEO_ENCODER | BO_USE_HW_VIDEO_DECODER |
Yiwei Zhangbbe1fd32022-07-20 20:44:22 +000045 BO_USE_CAMERA_READ | BO_USE_CAMERA_WRITE |
Jason Macnak80f664c2022-07-19 16:44:22 -070046 BO_USE_GPU_DATA_BUFFER | BO_USE_SENSOR_DIRECT_DATA);
Anders Delliene5bef532020-06-10 10:30:44 +010047 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
Matt Turner7790b232021-11-17 18:36:46 +000055static 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
Gurchetan Singh238001f2020-10-28 15:00:10 -070067INIT_DUMB_DRIVER(evdi)
Anders Delliene5bef532020-06-10 10:30:44 +010068INIT_DUMB_DRIVER(komeda)
69INIT_DUMB_DRIVER(marvell)
70INIT_DUMB_DRIVER(meson)
71INIT_DUMB_DRIVER(nouveau)
72INIT_DUMB_DRIVER(radeon)
Chen-Yu Tsaidd9c8642022-11-29 15:59:25 +080073INIT_DUMB_DRIVER_WITH_NAME(sun4i_drm, "sun4i-drm")
Anders Delliene5bef532020-06-10 10:30:44 +010074INIT_DUMB_DRIVER(synaptics)
Gurchetan Singh238001f2020-10-28 15:00:10 -070075INIT_DUMB_DRIVER(udl)
François-Denis Gonthiercea0b842020-05-22 18:02:24 -040076INIT_DUMB_DRIVER(vkms)
Chen-Yu Tsaidd9c8642022-11-29 15:59:25 +080077
78#ifndef DRV_ROCKCHIP
79INIT_DUMB_DRIVER(rockchip)
80#endif
81#ifndef DRV_MEDIATEK
82INIT_DUMB_DRIVER(mediatek)
83#endif