xref: /aosp_15_r20/external/virglrenderer/src/vrend_winsys_gbm.h (revision bbecb9d118dfdb95f99bd754f8fa9be01f189df3)
1 /**************************************************************************
2  *
3  * Copyright (C) 2019 Chromium.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included
13  * in all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
19  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21  * OTHER DEALINGS IN THE SOFTWARE.
22  *
23  **************************************************************************/
24 
25 #ifndef VIRGL_GBM_H
26 #define VIRGL_GBM_H
27 
28 #include "vrend_iov.h"
29 #include "virglrenderer.h"
30 
31 #ifdef GBM_MAX_PLANES
32 #define VIRGL_GBM_MAX_PLANES GBM_MAX_PLANES
33 #else
34 #define VIRGL_GBM_MAX_PLANES 4
35 #endif
36 
37 /* GBM_FORMAT_ABGR16161616F was added since mesa 20.0 */
38 #ifndef GBM_FORMAT_ABGR16161616F
39 #define GBM_FORMAT_ABGR16161616F __gbm_fourcc_code('A', 'B', '4', 'H') /* [63:0] A:B:G:R 16:16:16:16 little endian */
40 #endif
41 
42 #ifndef MINIGBM
43 
44 #define GBM_BO_USE_TEXTURING (1 << 5)
45 #define GBM_BO_USE_CAMERA_WRITE (1 << 6)
46 #define GBM_BO_USE_CAMERA_READ (1 << 7)
47 #define GBM_BO_USE_PROTECTED (1 << 8)
48 #define GBM_BO_USE_SW_READ_OFTEN (1 << 9)
49 #define GBM_BO_USE_SW_READ_RARELY (1 << 10)
50 #define GBM_BO_USE_SW_WRITE_OFTEN (1 << 11)
51 #define GBM_BO_USE_SW_WRITE_RARELY (1 << 12)
52 #define GBM_BO_USE_HW_VIDEO_DECODER (1 << 13)
53 #define GBM_BO_USE_HW_VIDEO_ENCODER (1 << 14)
54 #define GBM_TEST_ALLOC (1 << 15)
55 
56 #endif
57 
58 #ifdef ENABLE_MINIGBM_ALLOCATION
59 
60 #define GBM_DEV_TYPE_FLAG_DISCRETE (1u << 0) /* Discrete GPU. Separate chip, dedicated VRAM. */
61 #define GBM_DEV_TYPE_FLAG_DISPLAY (1u << 1) /* Device capable of display. */
62 #define GBM_DEV_TYPE_FLAG_3D (1u << 2) /* Device capable or 3D rendering. */
63 #define GBM_DEV_TYPE_FLAG_ARMSOC (1u << 3) /* Device on ARM SOC. */
64 #define GBM_DEV_TYPE_FLAG_USB (1u << 4) /* USB device, udl, evdi. */
65 #define GBM_DEV_TYPE_FLAG_BLOCKED (1u << 5) /* Unsuitable device e.g. vgem, udl, evdi. */
66 #define GBM_DEV_TYPE_FLAG_INTERNAL_LCD (1u << 6) /* Device is driving internal LCD. */
67 
68 struct gbm_device_info {
69 	uint32_t dev_type_flags;
70 	int dri_node_num; /* DRI node number (0..63), for easy matching of devices. */
71 	unsigned int connectors;
72 	unsigned int connected;
73 };
74 
75 #define GBM_DETECT_FLAG_CONNECTED (1u << 0) /* Check if any connectors are connected. SLOW! */
76 
77 #ifdef MINIGBM
78 int gbm_detect_device_info(unsigned int detect_flags, int fd, struct gbm_device_info *info);
79 int gbm_detect_device_info_path(unsigned int detect_flags, const char *dev_node,
80 				struct gbm_device_info *info);
81 
82 /*
83  * Select "default" device to use for graphics memory allocator.
84  */
85 int gbm_get_default_device_fd(void);
86 #else
87 #define gbm_detect_device_info(detect_flags, fd, info) -1
88 #define gbm_detect_device_info_path(detect_flags, dev_node, info) -1
89 #define gbm_get_default_device_fd() -1
90 #endif /* MINIGBM */
91 #endif /* ENABLE_MINIGBM_ALLOCATION */
92 
93 /*
94  * If fd >= 0, virglrenderer owns the fd since it was opened via a rendernode
95  * query. If fd < 0, the gbm device was opened with the fd provided by the
96  * (*get_drm_fd) hook.
97  */
98 
99 struct gbm_device;
100 struct gbm_bo;
101 
102 struct virgl_gbm {
103    int fd;
104    struct gbm_device *device;
105 };
106 
107 struct virgl_gbm *virgl_gbm_init(int fd);
108 
109 void virgl_gbm_fini(struct virgl_gbm *gbm);
110 
111 int virgl_gbm_convert_format(uint32_t *virgl_format, uint32_t *gbm_format);
112 
113 int virgl_gbm_transfer(struct gbm_bo *bo, uint32_t direction, const struct iovec *iovecs,
114                        uint32_t num_iovecs, const struct vrend_transfer_info *info);
115 
116 uint32_t virgl_gbm_convert_flags(uint32_t virgl_bind_flags);
117 
118 int virgl_gbm_export_fd(struct gbm_device *gbm, uint32_t handle, int32_t *out_fd);
119 
120 int virgl_gbm_export_query(struct gbm_bo *bo, struct virgl_renderer_export_query *query);
121 
122 int virgl_gbm_get_plane_width(struct gbm_bo *bo, int plane);
123 int virgl_gbm_get_plane_height(struct gbm_bo *bo, int plane);
124 int virgl_gbm_get_plane_bytes_per_pixel(struct gbm_bo *bo, int plane);
125 
126 bool virgl_gbm_external_allocation_preferred(uint32_t flags);
127 bool virgl_gbm_gpu_import_required(uint32_t flags);
128 
129 #endif
130