r600g: add support for virtual address space on cayman v11
[mesa.git] / src / gallium / winsys / radeon / drm / radeon_winsys.h
1 /*
2 * Copyright 2008 Corbin Simpson <MostAwesomeDude@gmail.com>
3 * Copyright 2010 Marek Olšák <maraeo@gmail.com>
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * on the rights to use, copy, modify, merge, publish, distribute, sub
9 * license, and/or sell copies of the Software, and to permit persons to whom
10 * the Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22 * USE OR OTHER DEALINGS IN THE SOFTWARE. */
23
24 #ifndef RADEON_WINSYS_H
25 #define RADEON_WINSYS_H
26
27 /* The public winsys interface header for the radeon driver. */
28
29 /* R300 features in DRM.
30 *
31 * 2.6.0:
32 * - Hyper-Z
33 * - GB_Z_PEQ_CONFIG on rv350->r4xx
34 * - R500 FG_ALPHA_VALUE
35 *
36 * 2.8.0:
37 * - R500 US_FORMAT regs
38 * - R500 ARGB2101010 colorbuffer
39 * - CMask and AA regs
40 * - R16F/RG16F
41 */
42
43 #include "pipebuffer/pb_bufmgr.h"
44 #include "pipe/p_defines.h"
45 #include "pipe/p_state.h"
46
47 #define RADEON_MAX_CMDBUF_DWORDS (16 * 1024)
48
49 #define RADEON_FLUSH_ASYNC (1 << 0)
50 #define RADEON_FLUSH_KEEP_TILING_FLAGS (1 << 1) /* needs DRM 2.12.0 */
51
52 /* Tiling flags. */
53 enum radeon_bo_layout {
54 RADEON_LAYOUT_LINEAR = 0,
55 RADEON_LAYOUT_TILED,
56 RADEON_LAYOUT_SQUARETILED,
57
58 RADEON_LAYOUT_UNKNOWN
59 };
60
61 enum radeon_bo_domain { /* bitfield */
62 RADEON_DOMAIN_GTT = 2,
63 RADEON_DOMAIN_VRAM = 4
64 };
65
66 enum radeon_bo_usage { /* bitfield */
67 RADEON_USAGE_READ = 2,
68 RADEON_USAGE_WRITE = 4,
69 RADEON_USAGE_READWRITE = RADEON_USAGE_READ | RADEON_USAGE_WRITE
70 };
71
72 struct winsys_handle;
73
74 struct radeon_winsys_cs_handle { /* for write_reloc etc. */
75 struct {
76 struct pb_buffer base;
77 } _private;
78
79 unsigned last_flush;
80 unsigned binding;
81 };
82
83 struct radeon_winsys_cs {
84 unsigned cdw; /* Number of used dwords. */
85 uint32_t *buf; /* The command buffer. */
86 };
87
88 struct radeon_info {
89 uint32_t pci_id;
90 uint32_t gart_size;
91 uint32_t vram_size;
92
93 uint32_t drm_major; /* version */
94 uint32_t drm_minor;
95 uint32_t drm_patchlevel;
96
97 uint32_t r300_num_gb_pipes;
98 uint32_t r300_num_z_pipes;
99
100 uint32_t r600_num_backends;
101 uint32_t r600_clock_crystal_freq;
102 uint32_t r600_tiling_config;
103 uint32_t r600_num_tile_pipes;
104 uint32_t r600_backend_map;
105 boolean r600_backend_map_valid;
106 boolean r600_virtual_address;
107 uint32_t r600_va_start;
108 uint32_t r600_ib_vm_max_size;
109 };
110
111 enum radeon_feature_id {
112 RADEON_FID_R300_HYPERZ_ACCESS, /* ZMask + HiZ */
113 RADEON_FID_R300_CMASK_ACCESS,
114 };
115
116 struct radeon_winsys {
117 /**
118 * Destroy this winsys.
119 *
120 * \param ws The winsys this function is called from.
121 */
122 void (*destroy)(struct radeon_winsys *ws);
123
124 /**
125 * Query an info structure from winsys.
126 *
127 * \param ws The winsys this function is called from.
128 * \param info Return structure
129 */
130 void (*query_info)(struct radeon_winsys *ws,
131 struct radeon_info *info);
132
133 /**************************************************************************
134 * Buffer management. Buffer attributes are mostly fixed over its lifetime.
135 *
136 * Remember that gallium gets to choose the interface it needs, and the
137 * window systems must then implement that interface (rather than the
138 * other way around...).
139 *************************************************************************/
140
141 /**
142 * Create a buffer object.
143 *
144 * \param ws The winsys this function is called from.
145 * \param size The size to allocate.
146 * \param alignment An alignment of the buffer in memory.
147 * \param bind A bitmask of the PIPE_BIND_* flags.
148 * \param domain A bitmask of the RADEON_DOMAIN_* flags.
149 * \return The created buffer object.
150 */
151 struct pb_buffer *(*buffer_create)(struct radeon_winsys *ws,
152 unsigned size,
153 unsigned alignment,
154 unsigned bind,
155 enum radeon_bo_domain domain);
156
157 struct radeon_winsys_cs_handle *(*buffer_get_cs_handle)(
158 struct pb_buffer *buf);
159
160 /**
161 * Map the entire data store of a buffer object into the client's address
162 * space.
163 *
164 * \param buf A winsys buffer object to map.
165 * \param cs A command stream to flush if the buffer is referenced by it.
166 * \param usage A bitmask of the PIPE_TRANSFER_* flags.
167 * \return The pointer at the beginning of the buffer.
168 */
169 void *(*buffer_map)(struct pb_buffer *buf,
170 struct radeon_winsys_cs *cs,
171 enum pipe_transfer_usage usage);
172
173 /**
174 * Unmap a buffer object from the client's address space.
175 *
176 * \param buf A winsys buffer object to unmap.
177 */
178 void (*buffer_unmap)(struct pb_buffer *buf);
179
180 /**
181 * Return TRUE if a buffer object is being used by the GPU.
182 *
183 * \param buf A winsys buffer object.
184 * \param usage Only check whether the buffer is busy for the given usage.
185 */
186 boolean (*buffer_is_busy)(struct pb_buffer *buf,
187 enum radeon_bo_usage usage);
188
189 /**
190 * Wait for a buffer object until it is not used by a GPU. This is
191 * equivalent to a fence placed after the last command using the buffer,
192 * and synchronizing to the fence.
193 *
194 * \param buf A winsys buffer object to wait for.
195 * \param usage Only wait until the buffer is idle for the given usage,
196 * but may still be busy for some other usage.
197 */
198 void (*buffer_wait)(struct pb_buffer *buf, enum radeon_bo_usage usage);
199
200 /**
201 * Return tiling flags describing a memory layout of a buffer object.
202 *
203 * \param buf A winsys buffer object to get the flags from.
204 * \param macrotile A pointer to the return value of the microtile flag.
205 * \param microtile A pointer to the return value of the macrotile flag.
206 *
207 * \note microtile and macrotile are not bitmasks!
208 */
209 void (*buffer_get_tiling)(struct pb_buffer *buf,
210 enum radeon_bo_layout *microtile,
211 enum radeon_bo_layout *macrotile);
212
213 /**
214 * Set tiling flags describing a memory layout of a buffer object.
215 *
216 * \param buf A winsys buffer object to set the flags for.
217 * \param cs A command stream to flush if the buffer is referenced by it.
218 * \param macrotile A macrotile flag.
219 * \param microtile A microtile flag.
220 * \param stride A stride of the buffer in bytes, for texturing.
221 *
222 * \note microtile and macrotile are not bitmasks!
223 */
224 void (*buffer_set_tiling)(struct pb_buffer *buf,
225 struct radeon_winsys_cs *cs,
226 enum radeon_bo_layout microtile,
227 enum radeon_bo_layout macrotile,
228 unsigned stride);
229
230 /**
231 * Get a winsys buffer from a winsys handle. The internal structure
232 * of the handle is platform-specific and only a winsys should access it.
233 *
234 * \param ws The winsys this function is called from.
235 * \param whandle A winsys handle pointer as was received from a state
236 * tracker.
237 * \param stride The returned buffer stride in bytes.
238 */
239 struct pb_buffer *(*buffer_from_handle)(struct radeon_winsys *ws,
240 struct winsys_handle *whandle,
241 unsigned *stride);
242
243 /**
244 * Get a winsys handle from a winsys buffer. The internal structure
245 * of the handle is platform-specific and only a winsys should access it.
246 *
247 * \param buf A winsys buffer object to get the handle from.
248 * \param whandle A winsys handle pointer.
249 * \param stride A stride of the buffer in bytes, for texturing.
250 * \return TRUE on success.
251 */
252 boolean (*buffer_get_handle)(struct pb_buffer *buf,
253 unsigned stride,
254 struct winsys_handle *whandle);
255
256 /**
257 * Return the virtual address of a buffer.
258 *
259 * \param buf A winsys buffer object
260 * \return virtual address
261 */
262 uint64_t (*buffer_get_virtual_address)(struct pb_buffer *buf);
263
264 /**************************************************************************
265 * Command submission.
266 *
267 * Each pipe context should create its own command stream and submit
268 * commands independently of other contexts.
269 *************************************************************************/
270
271 /**
272 * Create a command stream.
273 *
274 * \param ws The winsys this function is called from.
275 */
276 struct radeon_winsys_cs *(*cs_create)(struct radeon_winsys *ws);
277
278 /**
279 * Destroy a command stream.
280 *
281 * \param cs A command stream to destroy.
282 */
283 void (*cs_destroy)(struct radeon_winsys_cs *cs);
284
285 /**
286 * Add a new buffer relocation. Every relocation must first be added
287 * before it can be written.
288 *
289 * \param cs A command stream to add buffer for validation against.
290 * \param buf A winsys buffer to validate.
291 * \param usage Whether the buffer is used for read and/or write.
292 * \param domain Bitmask of the RADEON_DOMAIN_* flags.
293 * \return Relocation index.
294 */
295 unsigned (*cs_add_reloc)(struct radeon_winsys_cs *cs,
296 struct radeon_winsys_cs_handle *buf,
297 enum radeon_bo_usage usage,
298 enum radeon_bo_domain domain);
299
300 /**
301 * Return TRUE if there is enough memory in VRAM and GTT for the relocs
302 * added so far. If the validation fails, all the relocations which have
303 * been added since the last call of cs_validate will be removed and
304 * the CS will be flushed (provided there are still any relocations).
305 *
306 * \param cs A command stream to validate.
307 */
308 boolean (*cs_validate)(struct radeon_winsys_cs *cs);
309
310 /**
311 * Write a relocated dword to a command buffer.
312 *
313 * \param cs A command stream the relocation is written to.
314 * \param buf A winsys buffer to write the relocation for.
315 */
316 void (*cs_write_reloc)(struct radeon_winsys_cs *cs,
317 struct radeon_winsys_cs_handle *buf);
318
319 /**
320 * Flush a command stream.
321 *
322 * \param cs A command stream to flush.
323 * \param flags, RADEON_FLUSH_ASYNC or 0.
324 */
325 void (*cs_flush)(struct radeon_winsys_cs *cs, unsigned flags);
326
327 /**
328 * Set a flush callback which is called from winsys when flush is
329 * required.
330 *
331 * \param cs A command stream to set the callback for.
332 * \param flush A flush callback function associated with the command stream.
333 * \param user A user pointer that will be passed to the flush callback.
334 */
335 void (*cs_set_flush_callback)(struct radeon_winsys_cs *cs,
336 void (*flush)(void *ctx, unsigned flags),
337 void *ctx);
338
339 /**
340 * Return TRUE if a buffer is referenced by a command stream.
341 *
342 * \param cs A command stream.
343 * \param buf A winsys buffer.
344 */
345 boolean (*cs_is_buffer_referenced)(struct radeon_winsys_cs *cs,
346 struct radeon_winsys_cs_handle *buf);
347
348 /**
349 * Request access to a feature for a command stream.
350 *
351 * \param cs A command stream.
352 * \param fid Feature ID, one of RADEON_FID_*
353 * \param enable Whether to enable or disable the feature.
354 */
355 boolean (*cs_request_feature)(struct radeon_winsys_cs *cs,
356 enum radeon_feature_id fid,
357 boolean enable);
358 };
359
360 #endif