1037b3c26Smrg/* 2037b3c26Smrg * Copyright (C) 2014-2015 Etnaviv Project 3037b3c26Smrg * 4037b3c26Smrg * Permission is hereby granted, free of charge, to any person obtaining a 5037b3c26Smrg * copy of this software and associated documentation files (the "Software"), 6037b3c26Smrg * to deal in the Software without restriction, including without limitation 7037b3c26Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8037b3c26Smrg * and/or sell copies of the Software, and to permit persons to whom the 9037b3c26Smrg * Software is furnished to do so, subject to the following conditions: 10037b3c26Smrg * 11037b3c26Smrg * The above copyright notice and this permission notice (including the next 12037b3c26Smrg * paragraph) shall be included in all copies or substantial portions of the 13037b3c26Smrg * Software. 14037b3c26Smrg * 15037b3c26Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16037b3c26Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17037b3c26Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18037b3c26Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19037b3c26Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20037b3c26Smrg * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21037b3c26Smrg * SOFTWARE. 22037b3c26Smrg * 23037b3c26Smrg * Authors: 24037b3c26Smrg * Christian Gmeiner <christian.gmeiner@gmail.com> 25037b3c26Smrg */ 26037b3c26Smrg 27037b3c26Smrg#include "etnaviv_priv.h" 28037b3c26Smrg 297cdc0497Smrgdrm_public int etna_pipe_wait(struct etna_pipe *pipe, uint32_t timestamp, uint32_t ms) 30037b3c26Smrg{ 31037b3c26Smrg return etna_pipe_wait_ns(pipe, timestamp, ms * 1000000); 32037b3c26Smrg} 33037b3c26Smrg 347cdc0497Smrgdrm_public int etna_pipe_wait_ns(struct etna_pipe *pipe, uint32_t timestamp, uint64_t ns) 35037b3c26Smrg{ 36037b3c26Smrg struct etna_device *dev = pipe->gpu->dev; 37037b3c26Smrg int ret; 38037b3c26Smrg 39037b3c26Smrg struct drm_etnaviv_wait_fence req = { 40037b3c26Smrg .pipe = pipe->gpu->core, 41037b3c26Smrg .fence = timestamp, 42037b3c26Smrg }; 43037b3c26Smrg 44037b3c26Smrg if (ns == 0) 45037b3c26Smrg req.flags |= ETNA_WAIT_NONBLOCK; 46037b3c26Smrg 47037b3c26Smrg get_abs_timeout(&req.timeout, ns); 48037b3c26Smrg 49037b3c26Smrg ret = drmCommandWrite(dev->fd, DRM_ETNAVIV_WAIT_FENCE, &req, sizeof(req)); 50037b3c26Smrg if (ret) { 51037b3c26Smrg ERROR_MSG("wait-fence failed! %d (%s)", ret, strerror(errno)); 52037b3c26Smrg return ret; 53037b3c26Smrg } 54037b3c26Smrg 55037b3c26Smrg return 0; 56037b3c26Smrg} 57037b3c26Smrg 587cdc0497Smrgdrm_public void etna_pipe_del(struct etna_pipe *pipe) 59037b3c26Smrg{ 60037b3c26Smrg free(pipe); 61037b3c26Smrg} 62037b3c26Smrg 637cdc0497Smrgdrm_public struct etna_pipe *etna_pipe_new(struct etna_gpu *gpu, enum etna_pipe_id id) 64037b3c26Smrg{ 65037b3c26Smrg struct etna_pipe *pipe; 66037b3c26Smrg 67037b3c26Smrg pipe = calloc(1, sizeof(*pipe)); 68037b3c26Smrg if (!pipe) { 69037b3c26Smrg ERROR_MSG("allocation failed"); 70037b3c26Smrg goto fail; 71037b3c26Smrg } 72037b3c26Smrg 73037b3c26Smrg pipe->id = id; 74037b3c26Smrg pipe->gpu = gpu; 75037b3c26Smrg 76037b3c26Smrg return pipe; 77037b3c26Smrgfail: 78037b3c26Smrg return NULL; 79037b3c26Smrg} 80