freedreno: Use symbol visibility.
[platform/upstream/libdrm.git] / freedreno / freedreno_ringbuffer.c
1 /* -*- mode: C; c-file-style: "k&r"; tab-width 4; indent-tabs-mode: t; -*- */
2
3 /*
4  * Copyright (C) 2012 Rob Clark <robclark@freedesktop.org>
5  *
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:
12  *
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
15  * Software.
16  *
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
23  * SOFTWARE.
24  *
25  * Authors:
26  *    Rob Clark <robclark@freedesktop.org>
27  */
28
29 #include <assert.h>
30
31 #include "freedreno_drmif.h"
32 #include "freedreno_priv.h"
33 #include "freedreno_ringbuffer.h"
34
35 drm_public struct fd_ringbuffer *
36 fd_ringbuffer_new(struct fd_pipe *pipe, uint32_t size)
37 {
38         struct fd_ringbuffer *ring;
39
40         ring = pipe->funcs->ringbuffer_new(pipe, size);
41         if (!ring)
42                 return NULL;
43
44         ring->size = size;
45         ring->pipe = pipe;
46         ring->start = ring->funcs->hostptr(ring);
47         ring->end = &(ring->start[size/4]);
48
49         ring->cur = ring->last_start = ring->start;
50
51         return ring;
52 }
53
54 drm_public void fd_ringbuffer_del(struct fd_ringbuffer *ring)
55 {
56         ring->funcs->destroy(ring);
57 }
58
59 /* ringbuffers which are IB targets should set the toplevel rb (ie.
60  * the IB source) as it's parent before emitting reloc's, to ensure
61  * the bookkeeping works out properly.
62  */
63 drm_public void fd_ringbuffer_set_parent(struct fd_ringbuffer *ring,
64                                          struct fd_ringbuffer *parent)
65 {
66         ring->parent = parent;
67 }
68
69 drm_public void fd_ringbuffer_reset(struct fd_ringbuffer *ring)
70 {
71         uint32_t *start = ring->start;
72         if (ring->pipe->id == FD_PIPE_2D)
73                 start = &ring->start[0x140];
74         ring->cur = ring->last_start = start;
75         if (ring->funcs->reset)
76                 ring->funcs->reset(ring);
77 }
78
79 /* maybe get rid of this and use fd_ringmarker_flush() from DDX too? */
80 drm_public int fd_ringbuffer_flush(struct fd_ringbuffer *ring)
81 {
82         return ring->funcs->flush(ring, ring->last_start);
83 }
84
85 drm_public uint32_t fd_ringbuffer_timestamp(struct fd_ringbuffer *ring)
86 {
87         return ring->last_timestamp;
88 }
89
90 drm_public void fd_ringbuffer_reloc(struct fd_ringbuffer *ring,
91                                     const struct fd_reloc *reloc)
92 {
93         ring->funcs->emit_reloc(ring, reloc);
94 }
95
96 drm_public void
97 fd_ringbuffer_emit_reloc_ring(struct fd_ringbuffer *ring,
98                               struct fd_ringmarker *target,
99                               struct fd_ringmarker *end)
100 {
101         assert(target->ring == end->ring);
102         ring->funcs->emit_reloc_ring(ring, target, end);
103 }
104
105 drm_public struct fd_ringmarker * fd_ringmarker_new(struct fd_ringbuffer *ring)
106 {
107         struct fd_ringmarker *marker = NULL;
108
109         marker = calloc(1, sizeof(*marker));
110         if (!marker) {
111                 ERROR_MSG("allocation failed");
112                 return NULL;
113         }
114
115         marker->ring = ring;
116
117         fd_ringmarker_mark(marker);
118
119         return marker;
120 }
121
122 drm_public void fd_ringmarker_del(struct fd_ringmarker *marker)
123 {
124         free(marker);
125 }
126
127 drm_public void fd_ringmarker_mark(struct fd_ringmarker *marker)
128 {
129         marker->cur = marker->ring->cur;
130 }
131
132 drm_public uint32_t fd_ringmarker_dwords(struct fd_ringmarker *start,
133                                          struct fd_ringmarker *end)
134 {
135         return end->cur - start->cur;
136 }
137
138 drm_public int fd_ringmarker_flush(struct fd_ringmarker *marker)
139 {
140         struct fd_ringbuffer *ring = marker->ring;
141         return ring->funcs->flush(ring, marker->cur);
142 }