OSDN Git Service

minigbm/i915: Add support for I915_FORMAT_MOD_Y_TILED_CCS.
[android-x86/external-minigbm.git] / drv_priv.h
1 /*
2  * Copyright 2016 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
7 #ifndef DRV_PRIV_H
8 #define DRV_PRIV_H
9
10
11 #include <stdint.h>
12 #include <stdlib.h>
13 #include <sys/types.h>
14 #include <stdatomic.h>
15
16 #include "drv.h"
17
18 #ifndef DISABLE_LOCK
19 #define ATOMIC_LOCK(X) \
20 while (atomic_flag_test_and_set(X)) { \
21   }
22
23 #define ATOMIC_UNLOCK(X) \
24   atomic_flag_clear(X);
25 #else
26 #define ATOMIC_LOCK(X) ((void)0)
27 #define ATOMIC_UNLOCK(X) ((void)0)
28 #endif
29
30 struct bo {
31         struct driver *drv;
32         uint32_t width;
33         uint32_t height;
34         uint32_t format;
35         uint32_t tiling;
36         size_t num_planes;
37         union bo_handle handles[DRV_MAX_PLANES];
38         uint32_t offsets[DRV_MAX_PLANES];
39         uint32_t sizes[DRV_MAX_PLANES];
40         uint32_t strides[DRV_MAX_PLANES];
41         uint64_t format_modifiers[DRV_MAX_PLANES];
42         uint64_t use_flags;
43         size_t total_size;
44         void *priv;
45 };
46
47 struct kms_item {
48         uint32_t format;
49         uint64_t modifier;
50         uint64_t use_flags;
51 };
52
53 struct format_metadata {
54         uint32_t priority;
55         uint32_t tiling;
56         uint64_t modifier;
57 };
58
59 struct combination {
60         uint32_t format;
61         struct format_metadata metadata;
62         uint64_t use_flags;
63 };
64
65 struct combinations {
66         struct combination *data;
67         uint32_t size;
68         uint32_t allocations;
69 };
70
71 struct driver {
72         int fd;
73         struct backend *backend;
74         void *priv;
75         void *buffer_table;
76         void *map_table;
77         struct combinations combos;
78         atomic_flag driver_lock;
79 };
80
81 struct backend {
82         char *name;
83         int (*init)(struct driver *drv);
84         void (*close)(struct driver *drv);
85         int (*bo_create)(struct bo *bo, uint32_t width, uint32_t height, uint32_t format,
86                          uint64_t use_flags);
87         int (*bo_create_with_modifiers)(struct bo *bo, uint32_t width, uint32_t height,
88                                         uint32_t format, const uint64_t *modifiers, uint32_t count);
89         int (*bo_destroy)(struct bo *bo);
90         int (*bo_import)(struct bo *bo, struct drv_import_fd_data *data);
91         void *(*bo_map)(struct bo *bo, struct map_info *data, size_t plane, uint32_t map_flags);
92         int (*bo_unmap)(struct bo *bo, struct map_info *data);
93         int (*bo_invalidate)(struct bo *bo, struct map_info *data);
94         int (*bo_flush)(struct bo *bo, struct map_info *data);
95         uint32_t (*resolve_format)(uint32_t format, uint64_t use_flags);
96 };
97
98 // clang-format off
99 #define BO_USE_RENDER_MASK BO_USE_LINEAR | BO_USE_PROTECTED | BO_USE_RENDERING | \
100                            BO_USE_RENDERSCRIPT | BO_USE_SW_READ_OFTEN | BO_USE_SW_WRITE_OFTEN | \
101                            BO_USE_SW_READ_RARELY | BO_USE_SW_WRITE_RARELY | BO_USE_TEXTURE
102
103 #define BO_USE_TEXTURE_MASK BO_USE_LINEAR | BO_USE_PROTECTED | BO_USE_RENDERSCRIPT | \
104                             BO_USE_SW_READ_OFTEN | BO_USE_SW_WRITE_OFTEN | \
105                             BO_USE_SW_READ_RARELY | BO_USE_SW_WRITE_RARELY | BO_USE_TEXTURE
106
107 #define LINEAR_METADATA (struct format_metadata) { 0, 1, DRM_FORMAT_MOD_NONE }
108 // clang-format on
109
110 #endif