Debian Codegraph @

src/gallium/winsys/etnaviv/drm/etnaviv_drm_winsys.c

raw
1 /*
2 * Copyright (c) 2015 Etnaviv Project
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sub license,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the
12 * next paragraph) shall be included in all copies or substantial portions
13 * of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
23 * Authors:
24 * Christian Gmeiner <[email protected]>
25 */
26
27 #include <sys/stat.h>
28
29 #include "util/u_screen.h"
30
31 #include "etnaviv/etnaviv_screen.h"
32 #include "etnaviv_drm_public.h"
33
34 #include <stdio.h>
35
36
37 static struct pipe_screen *
38 screen_create(int gpu_fd, const struct pipe_screen_config *config, struct renderonly *ro)
39 {
40 struct etna_device *dev;
41 struct etna_gpu *gpu = NULL;
42 struct etna_gpu *npu = NULL;
43 int i;
44
45 dev = etna_device_new_dup(gpu_fd);
46 if (!dev) {
47 fprintf(stderr, "Error creating device\n");
48 return NULL;
49 }
50
51 for (i = 0; !gpu || !npu; i++) {
52 struct etna_core_info *info;
53 struct etna_gpu *core = etna_gpu_new(dev, i);
54
55 if (!core)
56 break;
57
58 info = etna_gpu_get_core_info(core);
59 if (!gpu && /* Look for a 3D capable GPU */
60 etna_core_has_feature(info, ETNA_FEATURE_CORE_GPU) &&
61 etna_core_has_feature(info, ETNA_FEATURE_PIPE_3D))
62 gpu = core;
63
64 if (!npu && etna_core_has_feature(info, ETNA_FEATURE_CORE_NPU))
65 npu = core;
66
67 if (gpu || npu)
68 continue;
69
70 etna_gpu_del(core);
71 }
72
73 if (!gpu && !npu) {
74 fprintf(stderr, "Error creating gpu or npu\n");
75 return NULL;
76 }
77
78 return etna_screen_create(dev, gpu, npu, ro);
79 }
80
81 struct pipe_screen *
82 etna_drm_screen_create_renderonly(int fd, struct renderonly *ro,
83 const struct pipe_screen_config *config)
84 {
85 return u_pipe_screen_lookup_or_create(fd, config, ro, screen_create);
86 }
87
88 struct pipe_screen *
89 etna_drm_screen_create(int fd)
90 {
91 return u_pipe_screen_lookup_or_create(fd, NULL, NULL, screen_create);
92 }