Merge remote branch 'vdpau/pipe-video' into pipe-video
[mesa.git] / src / gallium / winsys / r600 / drm / r600_priv.h
1 /*
2 * Copyright 2010 Jerome Glisse <glisse@freedesktop.org>
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
22 *
23 * Authors:
24 * Jerome Glisse
25 */
26 #ifndef R600_PRIV_H
27 #define R600_PRIV_H
28
29 #include <errno.h>
30 #include <stdint.h>
31 #include <stdlib.h>
32 #include <assert.h>
33 #include <util/u_double_list.h>
34 #include <util/u_inlines.h>
35 #include <os/os_thread.h>
36 #include "r600.h"
37
38 struct r600_bomgr;
39
40 struct radeon {
41 int fd;
42 int refcount;
43 unsigned device;
44 unsigned family;
45 enum chip_class chip_class;
46 struct r600_tiling_info tiling_info;
47 struct r600_bomgr *bomgr;
48 unsigned *cfence;
49 };
50
51 struct r600_reg {
52 unsigned opcode;
53 unsigned offset_base;
54 unsigned offset;
55 unsigned need_bo;
56 unsigned flush_flags;
57 unsigned flush_mask;
58 };
59
60 struct radeon_bo {
61 struct pipe_reference reference;
62 unsigned handle;
63 unsigned size;
64 unsigned alignment;
65 int map_count;
66 void *data;
67 struct list_head fencedlist;
68 unsigned fence;
69 struct r600_context *ctx;
70 boolean shared;
71 struct r600_reloc *reloc;
72 unsigned reloc_id;
73 unsigned last_flush;
74 };
75
76 struct r600_bo {
77 struct pipe_reference reference;
78 unsigned size;
79 unsigned tiling_flags;
80 unsigned kernel_pitch;
81 unsigned domains;
82 struct radeon_bo *bo;
83 unsigned fence;
84 /* manager data */
85 struct list_head list;
86 unsigned manager_id;
87 unsigned alignment;
88 unsigned offset;
89 int64_t start;
90 int64_t end;
91 };
92
93 struct r600_bomgr {
94 struct radeon *radeon;
95 unsigned usecs;
96 pipe_mutex mutex;
97 struct list_head delayed;
98 unsigned num_delayed;
99 };
100
101 /*
102 * r600_drm.c
103 */
104 struct radeon *r600_new(int fd, unsigned device);
105 void r600_delete(struct radeon *r600);
106
107 /*
108 * radeon_pciid.c
109 */
110 unsigned radeon_family_from_device(unsigned device);
111
112 /*
113 * radeon_bo.c
114 */
115 struct radeon_bo *radeon_bo(struct radeon *radeon, unsigned handle,
116 unsigned size, unsigned alignment);
117 void radeon_bo_reference(struct radeon *radeon, struct radeon_bo **dst,
118 struct radeon_bo *src);
119 int radeon_bo_wait(struct radeon *radeon, struct radeon_bo *bo);
120 int radeon_bo_busy(struct radeon *radeon, struct radeon_bo *bo, uint32_t *domain);
121 int radeon_bo_fencelist(struct radeon *radeon, struct radeon_bo **bolist, uint32_t num_bo);
122 int radeon_bo_get_tiling_flags(struct radeon *radeon,
123 struct radeon_bo *bo,
124 uint32_t *tiling_flags,
125 uint32_t *pitch);
126 int radeon_bo_get_name(struct radeon *radeon,
127 struct radeon_bo *bo,
128 uint32_t *name);
129
130 /*
131 * r600_hw_context.c
132 */
133 int r600_context_init_fence(struct r600_context *ctx);
134 void r600_context_bo_reloc(struct r600_context *ctx, u32 *pm4, struct r600_bo *rbo);
135 void r600_context_bo_flush(struct r600_context *ctx, unsigned flush_flags,
136 unsigned flush_mask, struct r600_bo *rbo);
137 struct r600_bo *r600_context_reg_bo(struct r600_context *ctx, unsigned offset);
138 int r600_context_add_block(struct r600_context *ctx, const struct r600_reg *reg, unsigned nreg);
139
140 /*
141 * r600_bo.c
142 */
143 void r600_bo_destroy(struct radeon *radeon, struct r600_bo *bo);
144
145 /*
146 * r600_bomgr.c
147 */
148 struct r600_bomgr *r600_bomgr_create(struct radeon *radeon, unsigned usecs);
149 void r600_bomgr_destroy(struct r600_bomgr *mgr);
150 bool r600_bomgr_bo_destroy(struct r600_bomgr *mgr, struct r600_bo *bo);
151 void r600_bomgr_bo_init(struct r600_bomgr *mgr, struct r600_bo *bo);
152 struct r600_bo *r600_bomgr_bo_create(struct r600_bomgr *mgr,
153 unsigned size,
154 unsigned alignment,
155 unsigned cfence);
156
157
158 /*
159 * helpers
160 */
161 #define CTX_RANGE_ID(ctx, offset) (((offset) >> (ctx)->hash_shift) & 255)
162 #define CTX_BLOCK_ID(ctx, offset) ((offset) & ((1 << (ctx)->hash_shift) - 1))
163
164 static void inline r600_context_reg(struct r600_context *ctx,
165 unsigned offset, unsigned value,
166 unsigned mask)
167 {
168 struct r600_range *range;
169 struct r600_block *block;
170 unsigned id;
171
172 range = &ctx->range[CTX_RANGE_ID(ctx, offset)];
173 block = range->blocks[CTX_BLOCK_ID(ctx, offset)];
174 id = (offset - block->start_offset) >> 2;
175 block->reg[id] &= ~mask;
176 block->reg[id] |= value;
177 if (!(block->status & R600_BLOCK_STATUS_DIRTY)) {
178 ctx->pm4_dirty_cdwords += block->pm4_ndwords;
179 block->status |= R600_BLOCK_STATUS_ENABLED;
180 block->status |= R600_BLOCK_STATUS_DIRTY;
181 LIST_ADDTAIL(&block->list,&ctx->dirty);
182 }
183 }
184
185 static inline void r600_context_block_emit_dirty(struct r600_context *ctx, struct r600_block *block)
186 {
187 int id;
188
189 for (int j = 0; j < block->nreg; j++) {
190 if (block->pm4_bo_index[j]) {
191 /* find relocation */
192 id = block->pm4_bo_index[j];
193 r600_context_bo_reloc(ctx,
194 &block->pm4[block->reloc[id].bo_pm4_index],
195 block->reloc[id].bo);
196 r600_context_bo_flush(ctx,
197 block->reloc[id].flush_flags,
198 block->reloc[id].flush_mask,
199 block->reloc[id].bo);
200 }
201 }
202 memcpy(&ctx->pm4[ctx->pm4_cdwords], block->pm4, block->pm4_ndwords * 4);
203 ctx->pm4_cdwords += block->pm4_ndwords;
204 block->status ^= R600_BLOCK_STATUS_DIRTY;
205 LIST_DELINIT(&block->list);
206 }
207
208 /*
209 * radeon_bo.c
210 */
211 static inline int radeon_bo_map(struct radeon *radeon, struct radeon_bo *bo)
212 {
213 bo->map_count++;
214 return 0;
215 }
216
217 static inline void radeon_bo_unmap(struct radeon *radeon, struct radeon_bo *bo)
218 {
219 bo->map_count--;
220 assert(bo->map_count >= 0);
221 }
222
223 /*
224 * r600_bo
225 */
226 static inline struct radeon_bo *r600_bo_get_bo(struct r600_bo *bo)
227 {
228 return bo->bo;
229 }
230
231 static unsigned inline r600_bo_get_handle(struct r600_bo *bo)
232 {
233 return bo->bo->handle;
234 }
235
236 static unsigned inline r600_bo_get_size(struct r600_bo *bo)
237 {
238 return bo->size;
239 }
240
241 /*
242 * fence
243 */
244 static inline bool fence_is_after(unsigned fence, unsigned ofence)
245 {
246 /* handle wrap around */
247 if (fence < 0x80000000 && ofence > 0x80000000)
248 return TRUE;
249 if (fence > ofence)
250 return TRUE;
251 return FALSE;
252 }
253
254 #endif