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 <christian.gmeiner@gmail.com>
25 */
26
27 #include <sys/stat.h>
28
29 #include "util/u_screen.h"
30
31 #include "etnaviv/etnaviv_screen.h"
32 #include "etnaviv/hw/common.xml.h"
33 #include "etnaviv_drm_public.h"
34
35 #include <stdio.h>
36
37
38 static struct pipe_screen *
screen_create(int gpu_fd,const struct pipe_screen_config * config,struct renderonly * ro)39 screen_create(int gpu_fd, const struct pipe_screen_config *config, struct renderonly *ro)
40 {
41 struct etna_device *dev;
42 struct etna_gpu *gpu;
43 uint64_t val;
44 int i;
45
46 dev = etna_device_new_dup(gpu_fd);
47 if (!dev) {
48 fprintf(stderr, "Error creating device\n");
49 return NULL;
50 }
51
52 for (i = 0;; i++) {
53 gpu = etna_gpu_new(dev, i);
54 if (!gpu) {
55 fprintf(stderr, "Error creating gpu\n");
56 return NULL;
57 }
58
59 /* Look for a 3D capable GPU */
60 int ret = etna_gpu_get_param(gpu, ETNA_GPU_FEATURES_0, &val);
61 if (ret == 0 && (val & chipFeatures_PIPE_3D))
62 break;
63
64 etna_gpu_del(gpu);
65 }
66
67 return etna_screen_create(dev, gpu, ro);
68 }
69
70 struct pipe_screen *
etna_drm_screen_create_renderonly(int fd,struct renderonly * ro,const struct pipe_screen_config * config)71 etna_drm_screen_create_renderonly(int fd, struct renderonly *ro,
72 const struct pipe_screen_config *config)
73 {
74 return u_pipe_screen_lookup_or_create(fd, config, ro, screen_create);
75 }
76
77 struct pipe_screen *
etna_drm_screen_create(int fd)78 etna_drm_screen_create(int fd)
79 {
80 return u_pipe_screen_lookup_or_create(fd, NULL, NULL, screen_create);
81 }
82