blob: df5c8e97b266ab5f50db92bc75098f97bc360c9c [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 Singha40ca9e2016-08-29 19:51:45 -070029 size_t total_size;
Gurchetan Singh46faf6b2016-08-05 14:40:07 -070030 void *priv;
31};
32
33struct driver {
34 int fd;
35 struct backend *backend;
36 void *priv;
Gurchetan Singh1647fbe2016-08-03 17:14:55 -070037 void *buffer_table;
Gurchetan Singh1a31e602016-10-06 10:58:00 -070038 void *map_table;
Gurchetan Singh27dd4702016-11-23 17:27:52 -080039 pthread_mutex_t driver_lock;
Gurchetan Singh46faf6b2016-08-05 14:40:07 -070040};
41
Gurchetan Singh6b41fb52017-03-01 20:14:39 -080042struct kms_item {
Gurchetan Singh179687e2016-10-28 10:07:35 -070043 uint32_t format;
44 uint64_t modifier;
45 uint64_t usage;
46};
47
Gurchetan Singh6b41fb52017-03-01 20:14:39 -080048struct format_metadata {
49 uint32_t priority;
50 uint32_t tiling;
51 uint64_t modifier;
52};
53
54struct combination {
55 uint32_t format;
56 struct format_metadata metadata;
57 uint64_t usage;
58};
59
60struct combinations {
61 struct combination *data;
62 uint32_t size;
63 uint32_t allocations;
Gurchetan Singh179687e2016-10-28 10:07:35 -070064};
65
Gurchetan Singh1b1d56a2017-03-10 16:25:23 -080066struct backend {
Gurchetan Singh46faf6b2016-08-05 14:40:07 -070067 char *name;
68 int (*init)(struct driver *drv);
69 void (*close)(struct driver *drv);
Gurchetan Singh1b1d56a2017-03-10 16:25:23 -080070 int (*bo_create)(struct bo *bo, uint32_t width, uint32_t height, uint32_t format,
71 uint32_t flags);
72 int (*bo_create_with_modifiers)(struct bo *bo, uint32_t width, uint32_t height,
73 uint32_t format, const uint64_t *modifiers, uint32_t count);
Gurchetan Singh71611d62017-01-03 16:49:56 -080074 int (*bo_destroy)(struct bo *bo);
75 int (*bo_import)(struct bo *bo, struct drv_import_fd_data *data);
Gurchetan Singh1b1d56a2017-03-10 16:25:23 -080076 void *(*bo_map)(struct bo *bo, struct map_info *data, size_t plane);
Gurchetan Singh44d1fe42016-12-14 08:51:28 -080077 int (*bo_unmap)(struct bo *bo, struct map_info *data);
Gurchetan Singhf3b22da2016-11-21 10:46:38 -080078 uint32_t (*resolve_format)(uint32_t format);
Gurchetan Singh6b41fb52017-03-01 20:14:39 -080079 struct combinations combos;
Gurchetan Singh46faf6b2016-08-05 14:40:07 -070080};
81
Gurchetan Singh8ac0c9a2017-05-15 09:34:22 -070082// clang-format off
83#define BO_USE_RENDER_MASK BO_USE_LINEAR | BO_USE_RENDERING | BO_USE_SW_READ_OFTEN | \
84 BO_USE_SW_WRITE_OFTEN | BO_USE_SW_READ_RARELY | \
85 BO_USE_SW_WRITE_RARELY | BO_USE_TEXTURE
86
87#define BO_USE_TEXTURE_MASK BO_USE_LINEAR | BO_USE_SW_READ_OFTEN | BO_USE_SW_WRITE_OFTEN | \
88 BO_USE_SW_READ_RARELY | BO_USE_SW_WRITE_RARELY | BO_USE_TEXTURE
89
90#define LINEAR_METADATA (struct format_metadata) { 0, 1, DRM_FORMAT_MOD_NONE }
91// clang-format on
92
Gurchetan Singh46faf6b2016-08-05 14:40:07 -070093#endif