1d722e3fbSopenharmony_ci/* -*- mode: C; c-file-style: "k&r"; tab-width 4; indent-tabs-mode: t; -*- */
2d722e3fbSopenharmony_ci
3d722e3fbSopenharmony_ci/*
4d722e3fbSopenharmony_ci * Copyright (C) 2012 Rob Clark <robclark@freedesktop.org>
5d722e3fbSopenharmony_ci *
6d722e3fbSopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
7d722e3fbSopenharmony_ci * copy of this software and associated documentation files (the "Software"),
8d722e3fbSopenharmony_ci * to deal in the Software without restriction, including without limitation
9d722e3fbSopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10d722e3fbSopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
11d722e3fbSopenharmony_ci * Software is furnished to do so, subject to the following conditions:
12d722e3fbSopenharmony_ci *
13d722e3fbSopenharmony_ci * The above copyright notice and this permission notice (including the next
14d722e3fbSopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the
15d722e3fbSopenharmony_ci * Software.
16d722e3fbSopenharmony_ci *
17d722e3fbSopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18d722e3fbSopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19d722e3fbSopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
20d722e3fbSopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21d722e3fbSopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22d722e3fbSopenharmony_ci * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23d722e3fbSopenharmony_ci * SOFTWARE.
24d722e3fbSopenharmony_ci *
25d722e3fbSopenharmony_ci * Authors:
26d722e3fbSopenharmony_ci *    Rob Clark <robclark@freedesktop.org>
27d722e3fbSopenharmony_ci */
28d722e3fbSopenharmony_ci
29d722e3fbSopenharmony_ci#include "freedreno_drmif.h"
30d722e3fbSopenharmony_ci#include "freedreno_priv.h"
31d722e3fbSopenharmony_ci
32d722e3fbSopenharmony_ci/**
33d722e3fbSopenharmony_ci * priority of zero is highest priority, and higher numeric values are
34d722e3fbSopenharmony_ci * lower priorities
35d722e3fbSopenharmony_ci */
36d722e3fbSopenharmony_cidrm_public struct fd_pipe *
37d722e3fbSopenharmony_cifd_pipe_new2(struct fd_device *dev, enum fd_pipe_id id, uint32_t prio)
38d722e3fbSopenharmony_ci{
39d722e3fbSopenharmony_ci	struct fd_pipe *pipe;
40d722e3fbSopenharmony_ci	uint64_t val;
41d722e3fbSopenharmony_ci
42d722e3fbSopenharmony_ci	if (id > FD_PIPE_MAX) {
43d722e3fbSopenharmony_ci		ERROR_MSG("invalid pipe id: %d", id);
44d722e3fbSopenharmony_ci		return NULL;
45d722e3fbSopenharmony_ci	}
46d722e3fbSopenharmony_ci
47d722e3fbSopenharmony_ci	if ((prio != 1) && (fd_device_version(dev) < FD_VERSION_SUBMIT_QUEUES)) {
48d722e3fbSopenharmony_ci		ERROR_MSG("invalid priority!");
49d722e3fbSopenharmony_ci		return NULL;
50d722e3fbSopenharmony_ci	}
51d722e3fbSopenharmony_ci
52d722e3fbSopenharmony_ci	pipe = dev->funcs->pipe_new(dev, id, prio);
53d722e3fbSopenharmony_ci	if (!pipe) {
54d722e3fbSopenharmony_ci		ERROR_MSG("allocation failed");
55d722e3fbSopenharmony_ci		return NULL;
56d722e3fbSopenharmony_ci	}
57d722e3fbSopenharmony_ci
58d722e3fbSopenharmony_ci	pipe->dev = dev;
59d722e3fbSopenharmony_ci	pipe->id = id;
60d722e3fbSopenharmony_ci	atomic_set(&pipe->refcnt, 1);
61d722e3fbSopenharmony_ci
62d722e3fbSopenharmony_ci	fd_pipe_get_param(pipe, FD_GPU_ID, &val);
63d722e3fbSopenharmony_ci	pipe->gpu_id = val;
64d722e3fbSopenharmony_ci
65d722e3fbSopenharmony_ci	return pipe;
66d722e3fbSopenharmony_ci}
67d722e3fbSopenharmony_ci
68d722e3fbSopenharmony_cidrm_public struct fd_pipe *
69d722e3fbSopenharmony_cifd_pipe_new(struct fd_device *dev, enum fd_pipe_id id)
70d722e3fbSopenharmony_ci{
71d722e3fbSopenharmony_ci	return fd_pipe_new2(dev, id, 1);
72d722e3fbSopenharmony_ci}
73d722e3fbSopenharmony_ci
74d722e3fbSopenharmony_cidrm_public struct fd_pipe * fd_pipe_ref(struct fd_pipe *pipe)
75d722e3fbSopenharmony_ci{
76d722e3fbSopenharmony_ci	atomic_inc(&pipe->refcnt);
77d722e3fbSopenharmony_ci	return pipe;
78d722e3fbSopenharmony_ci}
79d722e3fbSopenharmony_ci
80d722e3fbSopenharmony_cidrm_public void fd_pipe_del(struct fd_pipe *pipe)
81d722e3fbSopenharmony_ci{
82d722e3fbSopenharmony_ci	if (!atomic_dec_and_test(&pipe->refcnt))
83d722e3fbSopenharmony_ci		return;
84d722e3fbSopenharmony_ci	pipe->funcs->destroy(pipe);
85d722e3fbSopenharmony_ci}
86d722e3fbSopenharmony_ci
87d722e3fbSopenharmony_cidrm_public int fd_pipe_get_param(struct fd_pipe *pipe,
88d722e3fbSopenharmony_ci				 enum fd_param_id param, uint64_t *value)
89d722e3fbSopenharmony_ci{
90d722e3fbSopenharmony_ci	return pipe->funcs->get_param(pipe, param, value);
91d722e3fbSopenharmony_ci}
92d722e3fbSopenharmony_ci
93d722e3fbSopenharmony_cidrm_public int fd_pipe_wait(struct fd_pipe *pipe, uint32_t timestamp)
94d722e3fbSopenharmony_ci{
95d722e3fbSopenharmony_ci	return fd_pipe_wait_timeout(pipe, timestamp, ~0);
96d722e3fbSopenharmony_ci}
97d722e3fbSopenharmony_ci
98d722e3fbSopenharmony_cidrm_public int fd_pipe_wait_timeout(struct fd_pipe *pipe, uint32_t timestamp,
99d722e3fbSopenharmony_ci		uint64_t timeout)
100d722e3fbSopenharmony_ci{
101d722e3fbSopenharmony_ci	return pipe->funcs->wait(pipe, timestamp, timeout);
102d722e3fbSopenharmony_ci}
103