Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/gallium/winsys/kmsro/drm/kmsro_drm_winsys.c
4566 views
1
/*
2
* Copyright (C) 2016 Christian Gmeiner <[email protected]>
3
* Copyright (C) 2017 Broadcom
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 (including the next
13
* paragraph) shall be included in all copies or substantial portions of the
14
* Software.
15
*
16
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
* SOFTWARE.
23
*/
24
25
#include <fcntl.h>
26
#include <unistd.h>
27
28
#include "kmsro_drm_public.h"
29
#include "v3d/drm/v3d_drm_public.h"
30
#include "vc4/drm/vc4_drm_public.h"
31
#include "etnaviv/drm/etnaviv_drm_public.h"
32
#include "freedreno/drm/freedreno_drm_public.h"
33
#include "panfrost/drm/panfrost_drm_public.h"
34
#include "lima/drm/lima_drm_public.h"
35
#include "xf86drm.h"
36
37
#include "pipe/p_screen.h"
38
#include "renderonly/renderonly.h"
39
#include "util/u_memory.h"
40
41
static void kmsro_ro_destroy(struct renderonly *ro)
42
{
43
if (ro->gpu_fd >= 0)
44
close(ro->gpu_fd);
45
46
FREE(ro);
47
}
48
49
struct pipe_screen *kmsro_drm_screen_create(int fd,
50
const struct pipe_screen_config *config)
51
{
52
struct pipe_screen *screen = NULL;
53
struct renderonly *ro = CALLOC_STRUCT(renderonly);
54
55
if (!ro)
56
return NULL;
57
58
ro->kms_fd = fd;
59
ro->gpu_fd = -1;
60
ro->destroy = kmsro_ro_destroy;
61
62
#if defined(GALLIUM_VC4)
63
ro->gpu_fd = drmOpenWithType("vc4", NULL, DRM_NODE_RENDER);
64
if (ro->gpu_fd >= 0) {
65
/* Passes the vc4-allocated BO through to the KMS-only DRM device using
66
* PRIME buffer sharing. The VC4 BO must be linear, which the SCANOUT
67
* flag on allocation will have ensured.
68
*/
69
ro->create_for_resource = renderonly_create_gpu_import_for_resource;
70
screen = vc4_drm_screen_create_renderonly(ro, config);
71
if (!screen)
72
goto out_free;
73
74
return screen;
75
}
76
#endif
77
78
#if defined(GALLIUM_ETNAVIV)
79
ro->gpu_fd = drmOpenWithType("etnaviv", NULL, DRM_NODE_RENDER);
80
if (ro->gpu_fd >= 0) {
81
ro->create_for_resource = renderonly_create_kms_dumb_buffer_for_resource;
82
screen = etna_drm_screen_create_renderonly(ro);
83
if (!screen)
84
goto out_free;
85
86
return screen;
87
}
88
#endif
89
90
#if defined(GALLIUM_FREEDRENO)
91
ro->gpu_fd = drmOpenWithType("msm", NULL, DRM_NODE_RENDER);
92
if (ro->gpu_fd >= 0) {
93
ro->create_for_resource = renderonly_create_kms_dumb_buffer_for_resource;
94
screen = fd_drm_screen_create(ro->gpu_fd, ro);
95
if (!screen)
96
goto out_free;
97
98
return screen;
99
}
100
#endif
101
102
#if defined(GALLIUM_PANFROST)
103
ro->gpu_fd = drmOpenWithType("panfrost", NULL, DRM_NODE_RENDER);
104
105
if (ro->gpu_fd >= 0) {
106
ro->create_for_resource = renderonly_create_kms_dumb_buffer_for_resource;
107
screen = panfrost_drm_screen_create_renderonly(ro);
108
if (!screen)
109
goto out_free;
110
111
return screen;
112
}
113
#endif
114
115
#if defined(GALLIUM_LIMA)
116
ro->gpu_fd = drmOpenWithType("lima", NULL, DRM_NODE_RENDER);
117
if (ro->gpu_fd >= 0) {
118
ro->create_for_resource = renderonly_create_kms_dumb_buffer_for_resource;
119
screen = lima_drm_screen_create_renderonly(ro);
120
if (!screen)
121
goto out_free;
122
123
return screen;
124
}
125
#endif
126
127
#if defined(GALLIUM_V3D)
128
ro->gpu_fd = drmOpenWithType("v3d", NULL, DRM_NODE_RENDER);
129
if (ro->gpu_fd >= 0) {
130
ro->create_for_resource = renderonly_create_kms_dumb_buffer_for_resource;
131
screen = v3d_drm_screen_create_renderonly(ro, config);
132
if (!screen)
133
goto out_free;
134
135
return screen;
136
}
137
#endif
138
139
return screen;
140
141
out_free:
142
if (ro->gpu_fd >= 0)
143
close(ro->gpu_fd);
144
FREE(ro);
145
146
return NULL;
147
}
148
149