1 /* -*- mode: C; c-file-style: "k&r"; tab-width 4; indent-tabs-mode: t; -*- */
4 * Copyright (C) 2012 Rob Clark <robclark@freedesktop.org>
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 * Rob Clark <robclark@freedesktop.org>
35 #include "freedreno_drmif.h"
36 #include "freedreno_priv.h"
37 #include "freedreno_ringbuffer.h"
39 struct fd_ringbuffer *
40 fd_ringbuffer_new(struct fd_pipe *pipe, uint32_t size)
42 struct fd_ringbuffer *ring;
44 ring = pipe->funcs->ringbuffer_new(pipe, size);
50 ring->start = ring->funcs->hostptr(ring);
51 ring->end = &(ring->start[size/4]);
53 ring->cur = ring->last_start = ring->start;
58 void fd_ringbuffer_del(struct fd_ringbuffer *ring)
60 fd_ringbuffer_reset(ring);
61 ring->funcs->destroy(ring);
64 /* ringbuffers which are IB targets should set the toplevel rb (ie.
65 * the IB source) as it's parent before emitting reloc's, to ensure
66 * the bookkeeping works out properly.
68 void fd_ringbuffer_set_parent(struct fd_ringbuffer *ring,
69 struct fd_ringbuffer *parent)
71 ring->parent = parent;
74 void fd_ringbuffer_reset(struct fd_ringbuffer *ring)
76 uint32_t *start = ring->start;
77 if (ring->pipe->id == FD_PIPE_2D)
78 start = &ring->start[0x140];
79 ring->cur = ring->last_start = start;
80 if (ring->funcs->reset)
81 ring->funcs->reset(ring);
84 /* maybe get rid of this and use fd_ringmarker_flush() from DDX too? */
85 int fd_ringbuffer_flush(struct fd_ringbuffer *ring)
87 return ring->funcs->flush(ring, ring->last_start);
90 uint32_t fd_ringbuffer_timestamp(struct fd_ringbuffer *ring)
92 return ring->last_timestamp;
95 void fd_ringbuffer_reloc(struct fd_ringbuffer *ring,
96 const struct fd_reloc *reloc)
98 ring->funcs->emit_reloc(ring, reloc);
101 void fd_ringbuffer_emit_reloc_ring(struct fd_ringbuffer *ring,
102 struct fd_ringmarker *target, struct fd_ringmarker *end)
104 uint32_t submit_offset, size;
106 assert(target->ring == end->ring);
108 submit_offset = offset_bytes(target->cur, target->ring->start);
109 size = offset_bytes(end->cur, target->cur);
111 ring->funcs->emit_reloc_ring(ring, target->ring, submit_offset, size);
115 fd_ringbuffer_emit_reloc_ring_full(struct fd_ringbuffer *ring,
116 struct fd_ringbuffer *target, uint32_t cmd_idx)
118 uint32_t size = offset_bytes(target->cur, target->start);
119 assert(cmd_idx == 0);
120 ring->funcs->emit_reloc_ring(ring, target, 0, size);
124 struct fd_ringmarker * fd_ringmarker_new(struct fd_ringbuffer *ring)
126 struct fd_ringmarker *marker = NULL;
128 marker = calloc(1, sizeof(*marker));
130 ERROR_MSG("allocation failed");
136 marker->cur = marker->ring->cur;
141 void fd_ringmarker_del(struct fd_ringmarker *marker)
146 void fd_ringmarker_mark(struct fd_ringmarker *marker)
148 marker->cur = marker->ring->cur;
151 uint32_t fd_ringmarker_dwords(struct fd_ringmarker *start,
152 struct fd_ringmarker *end)
154 return end->cur - start->cur;
157 int fd_ringmarker_flush(struct fd_ringmarker *marker)
159 struct fd_ringbuffer *ring = marker->ring;
160 return ring->funcs->flush(ring, marker->cur);