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 *
screen_create(int gpu_fd,const struct pipe_screen_config * config,struct renderonly * ro)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 switch (info->type) {
60 case ETNA_CORE_GPU:
61 /* Look for a 3D capable GPU */
62 if (!gpu && etna_core_has_feature(info, ETNA_FEATURE_PIPE_3D)) {
63 gpu = core;
64 continue;
65 }
66 break;
67 case ETNA_CORE_NPU:
68 if (!npu) {
69 npu = core;
70 continue;
71 }
72 break;
73 default:
74 unreachable("invalid core type");
75 }
76
77 etna_gpu_del(core);
78 }
79
80 if (!gpu && !npu) {
81 fprintf(stderr, "Error creating gpu or npu\n");
82 return NULL;
83 }
84
85 return etna_screen_create(dev, gpu, npu, ro);
86 }
87
88 struct pipe_screen *
etna_drm_screen_create_renderonly(int fd,struct renderonly * ro,const struct pipe_screen_config * config)89 etna_drm_screen_create_renderonly(int fd, struct renderonly *ro,
90 const struct pipe_screen_config *config)
91 {
92 return u_pipe_screen_lookup_or_create(fd, config, ro, screen_create);
93 }
94
95 struct pipe_screen *
etna_drm_screen_create(int fd)96 etna_drm_screen_create(int fd)
97 {
98 return u_pipe_screen_lookup_or_create(fd, NULL, NULL, screen_create);
99 }
100