• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <gbm.h>
29 #include "vrend_iov.h"
30 #include "virglrenderer.h"
31 
32 #ifdef GBM_MAX_PLANES
33 #define VIRGL_GBM_MAX_PLANES GBM_MAX_PLANES
34 #else
35 #define VIRGL_GBM_MAX_PLANES 4
36 #endif
37 
38 /* GBM_FORMAT_ABGR16161616F was added since mesa 20.0 */
39 #ifndef GBM_FORMAT_ABGR16161616F
40 #define GBM_FORMAT_ABGR16161616F __gbm_fourcc_code('A', 'B', '4', 'H') /* [63:0] A:B:G:R 16:16:16:16 little endian */
41 #endif
42 
43 #ifndef MINIGBM
44 
45 #define GBM_BO_USE_TEXTURING (1 << 5)
46 #define GBM_BO_USE_CAMERA_WRITE (1 << 6)
47 #define GBM_BO_USE_CAMERA_READ (1 << 7)
48 #define GBM_BO_USE_PROTECTED (1 << 8)
49 #define GBM_BO_USE_SW_READ_OFTEN (1 << 9)
50 #define GBM_BO_USE_SW_READ_RARELY (1 << 10)
51 #define GBM_BO_USE_SW_WRITE_OFTEN (1 << 11)
52 #define GBM_BO_USE_SW_WRITE_RARELY (1 << 12)
53 #define GBM_BO_USE_HW_VIDEO_DECODER (1 << 13)
54 #define GBM_BO_USE_HW_VIDEO_ENCODER (1 << 14)
55 #define GBM_TEST_ALLOC (1 << 15)
56 
57 #endif
58 
59 #ifdef ENABLE_MINIGBM_ALLOCATION
60 
61 #define GBM_DEV_TYPE_FLAG_DISCRETE (1u << 0) /* Discrete GPU. Separate chip, dedicated VRAM. */
62 #define GBM_DEV_TYPE_FLAG_DISPLAY (1u << 1) /* Device capable of display. */
63 #define GBM_DEV_TYPE_FLAG_3D (1u << 2) /* Device capable or 3D rendering. */
64 #define GBM_DEV_TYPE_FLAG_ARMSOC (1u << 3) /* Device on ARM SOC. */
65 #define GBM_DEV_TYPE_FLAG_USB (1u << 4) /* USB device, udl, evdi. */
66 #define GBM_DEV_TYPE_FLAG_BLOCKED (1u << 5) /* Unsuitable device e.g. vgem, udl, evdi. */
67 #define GBM_DEV_TYPE_FLAG_INTERNAL_LCD (1u << 6) /* Device is driving internal LCD. */
68 
69 struct gbm_device_info {
70 	uint32_t dev_type_flags;
71 	int dri_node_num; /* DRI node number (0..63), for easy matching of devices. */
72 	unsigned int connectors;
73 	unsigned int connected;
74 };
75 
76 #define GBM_DETECT_FLAG_CONNECTED (1u << 0) /* Check if any connectors are connected. SLOW! */
77 
78 #ifdef MINIGBM
79 int gbm_detect_device_info(unsigned int detect_flags, int fd, struct gbm_device_info *info);
80 int gbm_detect_device_info_path(unsigned int detect_flags, const char *dev_node,
81 				struct gbm_device_info *info);
82 
83 /*
84  * Select "default" device to use for graphics memory allocator.
85  */
86 int gbm_get_default_device_fd(void);
87 #else
88 #define gbm_detect_device_info(detect_flags, fd, info) -1
89 #define gbm_detect_device_info_path(detect_flags, dev_node, info) -1
90 #define gbm_get_default_device_fd() -1
91 #endif /* MINIGBM */
92 #endif /* ENABLE_MINIGBM_ALLOCATION */
93 
94 /*
95  * If fd >= 0, virglrenderer owns the fd since it was opened via a rendernode
96  * query. If fd < 0, the gbm device was opened with the fd provided by the
97  * (*get_drm_fd) hook.
98  */
99 struct virgl_gbm {
100    int fd;
101    struct gbm_device *device;
102 };
103 
104 struct virgl_gbm *virgl_gbm_init(int fd);
105 
106 void virgl_gbm_fini(struct virgl_gbm *gbm);
107 
108 int virgl_gbm_convert_format(uint32_t *virgl_format, uint32_t *gbm_format);
109 
110 int virgl_gbm_transfer(struct gbm_bo *bo, uint32_t direction, const struct iovec *iovecs,
111                        uint32_t num_iovecs, const struct vrend_transfer_info *info);
112 
113 uint32_t virgl_gbm_convert_flags(uint32_t virgl_bind_flags);
114 
115 int virgl_gbm_export_fd(struct gbm_device *gbm, uint32_t handle, int32_t *out_fd);
116 
117 int virgl_gbm_export_query(struct gbm_bo *bo, struct virgl_renderer_export_query *query);
118 
119 int virgl_gbm_get_plane_width(struct gbm_bo *bo, int plane);
120 int virgl_gbm_get_plane_height(struct gbm_bo *bo, int plane);
121 int virgl_gbm_get_plane_bytes_per_pixel(struct gbm_bo *bo, int plane);
122 
123 bool virgl_gbm_external_allocation_preferred(uint32_t flags);
124 bool virgl_gbm_gpu_import_required(uint32_t flags);
125 
126 #endif
127