blob: cb244fc9d683deb1c6a462ebc7ab8f529a1930c0 [file] [log] [blame]
Gurchetan Singh46faf6b2016-08-05 14:40:07 -07001/*
Daniele Castagna7a755de2016-12-16 17:32:30 -05002 * Copyright 2016 The Chromium OS Authors. All rights reserved.
Gurchetan Singh46faf6b2016-08-05 14:40:07 -07003 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file.
5 */
6
7#ifndef DRV_PRIV_H
8#define DRV_PRIV_H
9
Gurchetan Singh2e786ad2016-08-24 18:31:23 -070010#include <pthread.h>
David Stevens26fe6822020-03-09 12:23:42 +000011#include <stdbool.h>
Gurchetan Singh46faf6b2016-08-05 14:40:07 -070012#include <stdint.h>
13#include <stdlib.h>
14#include <sys/types.h>
15
16#include "drv.h"
17
Gurchetan Singh298b7572019-09-19 09:55:18 -070018struct bo_metadata {
Gurchetan Singh46faf6b2016-08-05 14:40:07 -070019 uint32_t width;
20 uint32_t height;
21 uint32_t format;
22 uint32_t tiling;
23 size_t num_planes;
Gurchetan Singh46faf6b2016-08-05 14:40:07 -070024 uint32_t offsets[DRV_MAX_PLANES];
25 uint32_t sizes[DRV_MAX_PLANES];
26 uint32_t strides[DRV_MAX_PLANES];
Gurchetan Singh52155b42021-01-27 17:55:17 -080027 uint64_t format_modifier;
Gurchetan Singha1892b22017-09-28 16:40:52 -070028 uint64_t use_flags;
Gurchetan Singha40ca9e2016-08-29 19:51:45 -070029 size_t total_size;
Gurchetan Singh73c141e2021-01-21 14:51:19 -080030
31 /*
32 * Most of the following metadata is virtgpu cross_domain specific. However, that backend
33 * needs to know traditional metadata (strides, offsets) in addition to this backend
34 * specific metadata. It's easiest just to stuff all the metadata here rather than
35 * having two metadata structs.
36 */
Gurchetan Singh4e767d32021-08-25 10:24:50 -070037 uint32_t blob_id;
Gurchetan Singh73c141e2021-01-21 14:51:19 -080038 uint32_t map_info;
39 int32_t memory_idx;
40 int32_t physical_device_idx;
Gurchetan Singh298b7572019-09-19 09:55:18 -070041};
42
43struct bo {
44 struct driver *drv;
45 struct bo_metadata meta;
David Stevens26fe6822020-03-09 12:23:42 +000046 bool is_test_buffer;
Gurchetan Singh298b7572019-09-19 09:55:18 -070047 union bo_handle handles[DRV_MAX_PLANES];
Gurchetan Singh46faf6b2016-08-05 14:40:07 -070048 void *priv;
49};
50
Gurchetan Singh6b41fb52017-03-01 20:14:39 -080051struct format_metadata {
52 uint32_t priority;
53 uint32_t tiling;
54 uint64_t modifier;
55};
56
57struct combination {
58 uint32_t format;
59 struct format_metadata metadata;
Gurchetan Singha1892b22017-09-28 16:40:52 -070060 uint64_t use_flags;
Gurchetan Singh6b41fb52017-03-01 20:14:39 -080061};
62
Ege Mihmanli96b7d462017-09-19 20:13:26 -070063struct driver {
64 int fd;
Gurchetan Singh3e9d3832017-10-31 10:36:25 -070065 const struct backend *backend;
Ege Mihmanli96b7d462017-09-19 20:13:26 -070066 void *priv;
67 void *buffer_table;
Gurchetan Singhcfedbcc2017-11-02 17:32:00 -070068 struct drv_array *mappings;
Gurchetan Singhbc9a87d2017-11-03 17:17:35 -070069 struct drv_array *combos;
Ege Mihmanli96b7d462017-09-19 20:13:26 -070070 pthread_mutex_t driver_lock;
Pilar Molina Lopez28cf2f12020-11-12 18:19:42 -050071 bool compression;
Ege Mihmanli96b7d462017-09-19 20:13:26 -070072};
73
Gurchetan Singh1b1d56a2017-03-10 16:25:23 -080074struct backend {
Gurchetan Singh46faf6b2016-08-05 14:40:07 -070075 char *name;
76 int (*init)(struct driver *drv);
77 void (*close)(struct driver *drv);
Gurchetan Singh1b1d56a2017-03-10 16:25:23 -080078 int (*bo_create)(struct bo *bo, uint32_t width, uint32_t height, uint32_t format,
Gurchetan Singha1892b22017-09-28 16:40:52 -070079 uint64_t use_flags);
Gurchetan Singh1b1d56a2017-03-10 16:25:23 -080080 int (*bo_create_with_modifiers)(struct bo *bo, uint32_t width, uint32_t height,
81 uint32_t format, const uint64_t *modifiers, uint32_t count);
David Stevens26fe6822020-03-09 12:23:42 +000082 // Either both or neither _metadata functions must be implemented.
83 // If the functions are implemented, bo_create and bo_create_with_modifiers must not be.
84 int (*bo_compute_metadata)(struct bo *bo, uint32_t width, uint32_t height, uint32_t format,
85 uint64_t use_flags, const uint64_t *modifiers, uint32_t count);
86 int (*bo_create_from_metadata)(struct bo *bo);
Gurchetan Singh71611d62017-01-03 16:49:56 -080087 int (*bo_destroy)(struct bo *bo);
88 int (*bo_import)(struct bo *bo, struct drv_import_fd_data *data);
Gurchetan Singhee43c302017-11-14 18:20:27 -080089 void *(*bo_map)(struct bo *bo, struct vma *vma, size_t plane, uint32_t map_flags);
90 int (*bo_unmap)(struct bo *bo, struct vma *vma);
Gurchetan Singh47e629b2017-11-02 14:07:18 -070091 int (*bo_invalidate)(struct bo *bo, struct mapping *mapping);
92 int (*bo_flush)(struct bo *bo, struct mapping *mapping);
Yiwei Zhang9f390d92021-09-21 20:42:29 +000093 uint32_t (*resolve_format)(uint32_t format, uint64_t use_flags);
Yiwei Zhangc1413ea2021-09-17 08:20:21 +000094 uint64_t (*resolve_use_flags)(uint32_t format, uint64_t use_flags);
ChromeOS Developer44588bb2020-03-02 16:32:09 +010095 size_t (*num_planes_from_modifier)(struct driver *drv, uint32_t format, uint64_t modifier);
Gurchetan Singhbc4f0232019-06-27 20:05:54 -070096 int (*resource_info)(struct bo *bo, uint32_t strides[DRV_MAX_PLANES],
Yiwei Zhanga1e93fd2021-04-30 07:01:55 +000097 uint32_t offsets[DRV_MAX_PLANES], uint64_t *format_modifier);
Gurchetan Singh46faf6b2016-08-05 14:40:07 -070098};
99
Gurchetan Singh8ac0c9a2017-05-15 09:34:22 -0700100// clang-format off
Gurchetan Singhbbba9dd2020-10-12 17:31:10 -0700101#define BO_USE_RENDER_MASK (BO_USE_LINEAR | BO_USE_RENDERING | BO_USE_RENDERSCRIPT | \
102 BO_USE_SW_READ_OFTEN | BO_USE_SW_WRITE_OFTEN | BO_USE_SW_READ_RARELY | \
Rob Clark39d9f8b2021-04-01 14:27:22 -0700103 BO_USE_SW_WRITE_RARELY | BO_USE_TEXTURE | BO_USE_FRONT_RENDERING)
Gurchetan Singh8ac0c9a2017-05-15 09:34:22 -0700104
Gurchetan Singhbbba9dd2020-10-12 17:31:10 -0700105#define BO_USE_TEXTURE_MASK (BO_USE_LINEAR | BO_USE_RENDERSCRIPT | BO_USE_SW_READ_OFTEN | \
106 BO_USE_SW_WRITE_OFTEN | BO_USE_SW_READ_RARELY | \
Rob Clark39d9f8b2021-04-01 14:27:22 -0700107 BO_USE_SW_WRITE_RARELY | BO_USE_TEXTURE | BO_USE_FRONT_RENDERING)
Gurchetan Singh8ac0c9a2017-05-15 09:34:22 -0700108
David Stevensbaab6c82020-02-26 17:14:43 +0900109#define BO_USE_SW_MASK (BO_USE_SW_READ_OFTEN | BO_USE_SW_WRITE_OFTEN | \
Rob Clark39d9f8b2021-04-01 14:27:22 -0700110 BO_USE_SW_READ_RARELY | BO_USE_SW_WRITE_RARELY | BO_USE_FRONT_RENDERING)
David Stevensbaab6c82020-02-26 17:14:43 +0900111
112#define BO_USE_NON_GPU_HW (BO_USE_SCANOUT | BO_USE_CAMERA_WRITE | BO_USE_CAMERA_READ | \
Gurchetan Singhbbba9dd2020-10-12 17:31:10 -0700113 BO_USE_HW_VIDEO_ENCODER | BO_USE_HW_VIDEO_DECODER)
Dominik Behrfa17cdd2017-11-30 12:23:06 -0800114
Alistair Strachana50131a2018-03-19 14:04:23 -0700115#ifndef DRM_FORMAT_MOD_LINEAR
116#define DRM_FORMAT_MOD_LINEAR DRM_FORMAT_MOD_NONE
117#endif
118
Satyajitcdcebd82018-01-12 14:49:05 +0530119#define LINEAR_METADATA (struct format_metadata) { 1, 0, DRM_FORMAT_MOD_LINEAR }
Gurchetan Singh8ac0c9a2017-05-15 09:34:22 -0700120// clang-format on
121
Gurchetan Singh46faf6b2016-08-05 14:40:07 -0700122#endif