1e88f27b3Smrg/* -*- mode: C; c-file-style: "k&r"; tab-width 4; indent-tabs-mode: t; -*- */ 2e88f27b3Smrg 3e88f27b3Smrg/* 4e88f27b3Smrg * Copyright (C) 2012 Rob Clark <robclark@freedesktop.org> 5e88f27b3Smrg * 6e88f27b3Smrg * Permission is hereby granted, free of charge, to any person obtaining a 7e88f27b3Smrg * copy of this software and associated documentation files (the "Software"), 8e88f27b3Smrg * to deal in the Software without restriction, including without limitation 9e88f27b3Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10e88f27b3Smrg * and/or sell copies of the Software, and to permit persons to whom the 11e88f27b3Smrg * Software is furnished to do so, subject to the following conditions: 12e88f27b3Smrg * 13e88f27b3Smrg * The above copyright notice and this permission notice (including the next 14e88f27b3Smrg * paragraph) shall be included in all copies or substantial portions of the 15e88f27b3Smrg * Software. 16e88f27b3Smrg * 17e88f27b3Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18e88f27b3Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19e88f27b3Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20e88f27b3Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21e88f27b3Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22e88f27b3Smrg * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23e88f27b3Smrg * SOFTWARE. 24e88f27b3Smrg * 25e88f27b3Smrg * Authors: 26e88f27b3Smrg * Rob Clark <robclark@freedesktop.org> 27e88f27b3Smrg */ 28e88f27b3Smrg 29e88f27b3Smrg#include "freedreno_drmif.h" 30e88f27b3Smrg#include "freedreno_priv.h" 31e88f27b3Smrg 3200a23bdaSmrg/** 3300a23bdaSmrg * priority of zero is highest priority, and higher numeric values are 3400a23bdaSmrg * lower priorities 3500a23bdaSmrg */ 367cdc0497Smrgdrm_public struct fd_pipe * 3700a23bdaSmrgfd_pipe_new2(struct fd_device *dev, enum fd_pipe_id id, uint32_t prio) 38e88f27b3Smrg{ 39d8807b2fSmrg struct fd_pipe *pipe; 40037b3c26Smrg uint64_t val; 41e88f27b3Smrg 42e88f27b3Smrg if (id > FD_PIPE_MAX) { 43e88f27b3Smrg ERROR_MSG("invalid pipe id: %d", id); 44d8807b2fSmrg return NULL; 45e88f27b3Smrg } 46e88f27b3Smrg 4700a23bdaSmrg if ((prio != 1) && (fd_device_version(dev) < FD_VERSION_SUBMIT_QUEUES)) { 4800a23bdaSmrg ERROR_MSG("invalid priority!"); 4900a23bdaSmrg return NULL; 5000a23bdaSmrg } 5100a23bdaSmrg 5200a23bdaSmrg pipe = dev->funcs->pipe_new(dev, id, prio); 53e88f27b3Smrg if (!pipe) { 54e88f27b3Smrg ERROR_MSG("allocation failed"); 55d8807b2fSmrg return NULL; 56e88f27b3Smrg } 57e88f27b3Smrg 58e88f27b3Smrg pipe->dev = dev; 59e88f27b3Smrg pipe->id = id; 607cdc0497Smrg atomic_set(&pipe->refcnt, 1); 61e88f27b3Smrg 62037b3c26Smrg fd_pipe_get_param(pipe, FD_GPU_ID, &val); 63037b3c26Smrg pipe->gpu_id = val; 64037b3c26Smrg 65e88f27b3Smrg return pipe; 66e88f27b3Smrg} 67e88f27b3Smrg 687cdc0497Smrgdrm_public struct fd_pipe * 6900a23bdaSmrgfd_pipe_new(struct fd_device *dev, enum fd_pipe_id id) 7000a23bdaSmrg{ 7100a23bdaSmrg return fd_pipe_new2(dev, id, 1); 7200a23bdaSmrg} 7300a23bdaSmrg 747cdc0497Smrgdrm_public struct fd_pipe * fd_pipe_ref(struct fd_pipe *pipe) 757cdc0497Smrg{ 767cdc0497Smrg atomic_inc(&pipe->refcnt); 777cdc0497Smrg return pipe; 787cdc0497Smrg} 797cdc0497Smrg 807cdc0497Smrgdrm_public void fd_pipe_del(struct fd_pipe *pipe) 81e88f27b3Smrg{ 827cdc0497Smrg if (!atomic_dec_and_test(&pipe->refcnt)) 837cdc0497Smrg return; 84e88f27b3Smrg pipe->funcs->destroy(pipe); 85e88f27b3Smrg} 86e88f27b3Smrg 877cdc0497Smrgdrm_public int fd_pipe_get_param(struct fd_pipe *pipe, 88baaff307Smrg enum fd_param_id param, uint64_t *value) 89e88f27b3Smrg{ 90e88f27b3Smrg return pipe->funcs->get_param(pipe, param, value); 91e88f27b3Smrg} 92e88f27b3Smrg 937cdc0497Smrgdrm_public int fd_pipe_wait(struct fd_pipe *pipe, uint32_t timestamp) 94e88f27b3Smrg{ 953f012e29Smrg return fd_pipe_wait_timeout(pipe, timestamp, ~0); 963f012e29Smrg} 973f012e29Smrg 987cdc0497Smrgdrm_public int fd_pipe_wait_timeout(struct fd_pipe *pipe, uint32_t timestamp, 993f012e29Smrg uint64_t timeout) 1003f012e29Smrg{ 1013f012e29Smrg return pipe->funcs->wait(pipe, timestamp, timeout); 102e88f27b3Smrg} 103