xref: /third_party/libdrm/etnaviv/etnaviv_pipe.c (revision d722e3fb)
1d722e3fbSopenharmony_ci/*
2d722e3fbSopenharmony_ci * Copyright (C) 2014-2015 Etnaviv Project
3d722e3fbSopenharmony_ci *
4d722e3fbSopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
5d722e3fbSopenharmony_ci * copy of this software and associated documentation files (the "Software"),
6d722e3fbSopenharmony_ci * to deal in the Software without restriction, including without limitation
7d722e3fbSopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8d722e3fbSopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
9d722e3fbSopenharmony_ci * Software is furnished to do so, subject to the following conditions:
10d722e3fbSopenharmony_ci *
11d722e3fbSopenharmony_ci * The above copyright notice and this permission notice (including the next
12d722e3fbSopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the
13d722e3fbSopenharmony_ci * Software.
14d722e3fbSopenharmony_ci *
15d722e3fbSopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16d722e3fbSopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17d722e3fbSopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18d722e3fbSopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19d722e3fbSopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20d722e3fbSopenharmony_ci * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21d722e3fbSopenharmony_ci * SOFTWARE.
22d722e3fbSopenharmony_ci *
23d722e3fbSopenharmony_ci * Authors:
24d722e3fbSopenharmony_ci *    Christian Gmeiner <christian.gmeiner@gmail.com>
25d722e3fbSopenharmony_ci */
26d722e3fbSopenharmony_ci
27d722e3fbSopenharmony_ci#include "etnaviv_priv.h"
28d722e3fbSopenharmony_ci
29d722e3fbSopenharmony_cidrm_public int etna_pipe_wait(struct etna_pipe *pipe, uint32_t timestamp, uint32_t ms)
30d722e3fbSopenharmony_ci{
31d722e3fbSopenharmony_ci	return etna_pipe_wait_ns(pipe, timestamp, ms * 1000000);
32d722e3fbSopenharmony_ci}
33d722e3fbSopenharmony_ci
34d722e3fbSopenharmony_cidrm_public int etna_pipe_wait_ns(struct etna_pipe *pipe, uint32_t timestamp, uint64_t ns)
35d722e3fbSopenharmony_ci{
36d722e3fbSopenharmony_ci	struct etna_device *dev = pipe->gpu->dev;
37d722e3fbSopenharmony_ci	int ret;
38d722e3fbSopenharmony_ci
39d722e3fbSopenharmony_ci	struct drm_etnaviv_wait_fence req = {
40d722e3fbSopenharmony_ci		.pipe = pipe->gpu->core,
41d722e3fbSopenharmony_ci		.fence = timestamp,
42d722e3fbSopenharmony_ci	};
43d722e3fbSopenharmony_ci
44d722e3fbSopenharmony_ci	if (ns == 0)
45d722e3fbSopenharmony_ci		req.flags |= ETNA_WAIT_NONBLOCK;
46d722e3fbSopenharmony_ci
47d722e3fbSopenharmony_ci	get_abs_timeout(&req.timeout, ns);
48d722e3fbSopenharmony_ci
49d722e3fbSopenharmony_ci	ret = drmCommandWrite(dev->fd, DRM_ETNAVIV_WAIT_FENCE, &req, sizeof(req));
50d722e3fbSopenharmony_ci	if (ret) {
51d722e3fbSopenharmony_ci		ERROR_MSG("wait-fence failed! %d (%s)", ret, strerror(errno));
52d722e3fbSopenharmony_ci		return ret;
53d722e3fbSopenharmony_ci	}
54d722e3fbSopenharmony_ci
55d722e3fbSopenharmony_ci	return 0;
56d722e3fbSopenharmony_ci}
57d722e3fbSopenharmony_ci
58d722e3fbSopenharmony_cidrm_public void etna_pipe_del(struct etna_pipe *pipe)
59d722e3fbSopenharmony_ci{
60d722e3fbSopenharmony_ci	free(pipe);
61d722e3fbSopenharmony_ci}
62d722e3fbSopenharmony_ci
63d722e3fbSopenharmony_cidrm_public struct etna_pipe *etna_pipe_new(struct etna_gpu *gpu, enum etna_pipe_id id)
64d722e3fbSopenharmony_ci{
65d722e3fbSopenharmony_ci	struct etna_pipe *pipe;
66d722e3fbSopenharmony_ci
67d722e3fbSopenharmony_ci	pipe = calloc(1, sizeof(*pipe));
68d722e3fbSopenharmony_ci	if (!pipe) {
69d722e3fbSopenharmony_ci		ERROR_MSG("allocation failed");
70d722e3fbSopenharmony_ci		goto fail;
71d722e3fbSopenharmony_ci	}
72d722e3fbSopenharmony_ci
73d722e3fbSopenharmony_ci	pipe->id = id;
74d722e3fbSopenharmony_ci	pipe->gpu = gpu;
75d722e3fbSopenharmony_ci
76d722e3fbSopenharmony_ci	return pipe;
77d722e3fbSopenharmony_cifail:
78d722e3fbSopenharmony_ci	return NULL;
79d722e3fbSopenharmony_ci}
80