blob: 18a289cb9c2f49ba6ba4104fcfeb87dc791e487d [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>
Gurchetan Singh46faf6b2016-08-05 14:40:07 -070011#include <stdint.h>
12#include <stdlib.h>
13#include <sys/types.h>
14
15#include "drv.h"
16
Gurchetan Singh1b1d56a2017-03-10 16:25:23 -080017struct bo {
Gurchetan Singh46faf6b2016-08-05 14:40:07 -070018 struct driver *drv;
19 uint32_t width;
20 uint32_t height;
21 uint32_t format;
22 uint32_t tiling;
23 size_t num_planes;
24 union bo_handle handles[DRV_MAX_PLANES];
25 uint32_t offsets[DRV_MAX_PLANES];
26 uint32_t sizes[DRV_MAX_PLANES];
27 uint32_t strides[DRV_MAX_PLANES];
28 uint64_t format_modifiers[DRV_MAX_PLANES];
Gurchetan Singha1892b22017-09-28 16:40:52 -070029 uint64_t use_flags;
Gurchetan Singha40ca9e2016-08-29 19:51:45 -070030 size_t total_size;
Gurchetan Singh46faf6b2016-08-05 14:40:07 -070031 void *priv;
32};
33
Gurchetan Singh6b41fb52017-03-01 20:14:39 -080034struct kms_item {
Gurchetan Singh179687e2016-10-28 10:07:35 -070035 uint32_t format;
36 uint64_t modifier;
Gurchetan Singha1892b22017-09-28 16:40:52 -070037 uint64_t use_flags;
Gurchetan Singh179687e2016-10-28 10:07:35 -070038};
39
Gurchetan Singh6b41fb52017-03-01 20:14:39 -080040struct format_metadata {
41 uint32_t priority;
42 uint32_t tiling;
43 uint64_t modifier;
44};
45
46struct combination {
47 uint32_t format;
48 struct format_metadata metadata;
Gurchetan Singha1892b22017-09-28 16:40:52 -070049 uint64_t use_flags;
Gurchetan Singh6b41fb52017-03-01 20:14:39 -080050};
51
Ege Mihmanli96b7d462017-09-19 20:13:26 -070052struct driver {
53 int fd;
Gurchetan Singh3e9d3832017-10-31 10:36:25 -070054 const struct backend *backend;
Ege Mihmanli96b7d462017-09-19 20:13:26 -070055 void *priv;
56 void *buffer_table;
Gurchetan Singhcfedbcc2017-11-02 17:32:00 -070057 struct drv_array *mappings;
Gurchetan Singhbc9a87d2017-11-03 17:17:35 -070058 struct drv_array *combos;
Ege Mihmanli96b7d462017-09-19 20:13:26 -070059 pthread_mutex_t driver_lock;
60};
61
Gurchetan Singh1b1d56a2017-03-10 16:25:23 -080062struct backend {
Gurchetan Singh46faf6b2016-08-05 14:40:07 -070063 char *name;
64 int (*init)(struct driver *drv);
65 void (*close)(struct driver *drv);
Gurchetan Singh1b1d56a2017-03-10 16:25:23 -080066 int (*bo_create)(struct bo *bo, uint32_t width, uint32_t height, uint32_t format,
Gurchetan Singha1892b22017-09-28 16:40:52 -070067 uint64_t use_flags);
Gurchetan Singh1b1d56a2017-03-10 16:25:23 -080068 int (*bo_create_with_modifiers)(struct bo *bo, uint32_t width, uint32_t height,
69 uint32_t format, const uint64_t *modifiers, uint32_t count);
Gurchetan Singh71611d62017-01-03 16:49:56 -080070 int (*bo_destroy)(struct bo *bo);
71 int (*bo_import)(struct bo *bo, struct drv_import_fd_data *data);
Gurchetan Singhee43c302017-11-14 18:20:27 -080072 void *(*bo_map)(struct bo *bo, struct vma *vma, size_t plane, uint32_t map_flags);
73 int (*bo_unmap)(struct bo *bo, struct vma *vma);
Gurchetan Singh47e629b2017-11-02 14:07:18 -070074 int (*bo_invalidate)(struct bo *bo, struct mapping *mapping);
75 int (*bo_flush)(struct bo *bo, struct mapping *mapping);
Gurchetan Singha1892b22017-09-28 16:40:52 -070076 uint32_t (*resolve_format)(uint32_t format, uint64_t use_flags);
Gurchetan Singh46faf6b2016-08-05 14:40:07 -070077};
78
Gurchetan Singh8ac0c9a2017-05-15 09:34:22 -070079// clang-format off
Tomasz Figae0807b12017-08-04 12:50:03 +090080#define BO_USE_RENDER_MASK BO_USE_LINEAR | BO_USE_PROTECTED | BO_USE_RENDERING | \
81 BO_USE_RENDERSCRIPT | BO_USE_SW_READ_OFTEN | BO_USE_SW_WRITE_OFTEN | \
82 BO_USE_SW_READ_RARELY | BO_USE_SW_WRITE_RARELY | BO_USE_TEXTURE
Gurchetan Singh8ac0c9a2017-05-15 09:34:22 -070083
Tomasz Figae0807b12017-08-04 12:50:03 +090084#define BO_USE_TEXTURE_MASK BO_USE_LINEAR | BO_USE_PROTECTED | BO_USE_RENDERSCRIPT | \
85 BO_USE_SW_READ_OFTEN | BO_USE_SW_WRITE_OFTEN | \
86 BO_USE_SW_READ_RARELY | BO_USE_SW_WRITE_RARELY | BO_USE_TEXTURE
Gurchetan Singh8ac0c9a2017-05-15 09:34:22 -070087
88#define LINEAR_METADATA (struct format_metadata) { 0, 1, DRM_FORMAT_MOD_NONE }
89// clang-format on
90
Gurchetan Singh46faf6b2016-08-05 14:40:07 -070091#endif