• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2014-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, sublicense,
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 next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * 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 NONINFRINGEMENT.  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 FROM,
20  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21  * SOFTWARE.
22  *
23  * Authors:
24  *    Christian Gmeiner <christian.gmeiner@gmail.com>
25  */
26 
27 #ifdef HAVE_CONFIG_H
28 # include <config.h>
29 #endif
30 
31 #include "etnaviv_priv.h"
32 
etna_pipe_wait(struct etna_pipe * pipe,uint32_t timestamp,uint32_t ms)33 int etna_pipe_wait(struct etna_pipe *pipe, uint32_t timestamp, uint32_t ms)
34 {
35 	return etna_pipe_wait_ns(pipe, timestamp, ms * 1000000);
36 }
37 
etna_pipe_wait_ns(struct etna_pipe * pipe,uint32_t timestamp,uint64_t ns)38 int etna_pipe_wait_ns(struct etna_pipe *pipe, uint32_t timestamp, uint64_t ns)
39 {
40 	struct etna_device *dev = pipe->gpu->dev;
41 	int ret;
42 
43 	struct drm_etnaviv_wait_fence req = {
44 		.pipe = pipe->gpu->core,
45 		.fence = timestamp,
46 	};
47 
48 	if (ns == 0)
49 		req.flags |= ETNA_WAIT_NONBLOCK;
50 
51 	get_abs_timeout(&req.timeout, ns);
52 
53 	ret = drmCommandWrite(dev->fd, DRM_ETNAVIV_WAIT_FENCE, &req, sizeof(req));
54 	if (ret) {
55 		ERROR_MSG("wait-fence failed! %d (%s)", ret, strerror(errno));
56 		return ret;
57 	}
58 
59 	return 0;
60 }
61 
etna_pipe_del(struct etna_pipe * pipe)62 void etna_pipe_del(struct etna_pipe *pipe)
63 {
64 	free(pipe);
65 }
66 
etna_pipe_new(struct etna_gpu * gpu,enum etna_pipe_id id)67 struct etna_pipe *etna_pipe_new(struct etna_gpu *gpu, enum etna_pipe_id id)
68 {
69 	struct etna_pipe *pipe;
70 
71 	pipe = calloc(1, sizeof(*pipe));
72 	if (!pipe) {
73 		ERROR_MSG("allocation failed");
74 		goto fail;
75 	}
76 
77 	pipe->id = id;
78 	pipe->gpu = gpu;
79 
80 	return pipe;
81 fail:
82 	return NULL;
83 }
84