• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 Christian Gmeiner <christian.gmeiner@gmail.com>
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 
kmsro_drm_screen_create(int fd,const struct pipe_screen_config * config)40 struct pipe_screen *kmsro_drm_screen_create(int fd,
41                                             const struct pipe_screen_config *config)
42 {
43    struct pipe_screen *screen = NULL;
44    struct renderonly ro = {
45       .kms_fd = fd,
46       .gpu_fd = -1,
47    };
48 
49 #if defined(GALLIUM_VC4)
50    ro.gpu_fd = drmOpenWithType("vc4", NULL, DRM_NODE_RENDER);
51    if (ro.gpu_fd >= 0) {
52       /* Passes the vc4-allocated BO through to the KMS-only DRM device using
53        * PRIME buffer sharing.  The VC4 BO must be linear, which the SCANOUT
54        * flag on allocation will have ensured.
55        */
56       ro.create_for_resource = renderonly_create_gpu_import_for_resource,
57       screen = vc4_drm_screen_create_renderonly(&ro, config);
58       if (!screen)
59          close(ro.gpu_fd);
60 
61       return screen;
62    }
63 #endif
64 
65 #if defined(GALLIUM_ETNAVIV)
66    ro.gpu_fd = drmOpenWithType("etnaviv", NULL, DRM_NODE_RENDER);
67    if (ro.gpu_fd >= 0) {
68       ro.create_for_resource = renderonly_create_kms_dumb_buffer_for_resource,
69       screen = etna_drm_screen_create_renderonly(&ro);
70       if (!screen)
71          close(ro.gpu_fd);
72 
73       return screen;
74    }
75 #endif
76 
77 #if defined(GALLIUM_FREEDRENO)
78    ro.gpu_fd = drmOpenWithType("msm", NULL, DRM_NODE_RENDER);
79    if (ro.gpu_fd >= 0) {
80       ro.create_for_resource = renderonly_create_kms_dumb_buffer_for_resource,
81       screen = fd_drm_screen_create(ro.gpu_fd, &ro);
82       if (!screen)
83          close(ro.gpu_fd);
84 
85       return screen;
86    }
87 #endif
88 
89 #if defined(GALLIUM_PANFROST)
90    ro.gpu_fd = drmOpenWithType("panfrost", NULL, DRM_NODE_RENDER);
91 
92    if (ro.gpu_fd >= 0) {
93       ro.create_for_resource = renderonly_create_kms_dumb_buffer_for_resource,
94       screen = panfrost_drm_screen_create_renderonly(&ro);
95       if (!screen)
96          close(ro.gpu_fd);
97 
98       return screen;
99    }
100 #endif
101 
102 #if defined(GALLIUM_LIMA)
103    ro.gpu_fd = drmOpenWithType("lima", NULL, DRM_NODE_RENDER);
104    if (ro.gpu_fd >= 0) {
105       ro.create_for_resource = renderonly_create_kms_dumb_buffer_for_resource,
106       screen = lima_drm_screen_create_renderonly(&ro);
107       if (!screen)
108          close(ro.gpu_fd);
109 
110       return screen;
111    }
112 #endif
113 
114 #if defined(GALLIUM_V3D)
115    ro.gpu_fd = drmOpenWithType("v3d", NULL, DRM_NODE_RENDER);
116    if (ro.gpu_fd >= 0) {
117       ro.create_for_resource = renderonly_create_kms_dumb_buffer_for_resource,
118       screen = v3d_drm_screen_create_renderonly(&ro, config);
119       if (!screen)
120          close(ro.gpu_fd);
121 
122       return screen;
123    }
124 #endif
125 
126    return screen;
127 }
128