r300g: fix an invalid pointer in free
[mesa.git] / src / gallium / drivers / r300 / r300_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 R300_WINSYS_H
25 #define R300_WINSYS_H
26
27 /* The public winsys interface header for the r300 pipe driver.
28 * Any winsys hosting this pipe needs to implement r300_winsys_screen and then
29 * call r300_screen_create to start things. */
30
31 #include "pipe/p_defines.h"
32 #include "pipe/p_state.h"
33
34 #include "r300_defines.h"
35
36 struct r300_winsys_screen;
37
38 struct r300_winsys_buffer;
39
40 struct r300_winsys_cs {
41 uint32_t *ptr; /* Pointer to the beginning of the CS. */
42 unsigned cdw; /* Number of used dwords. */
43 unsigned ndw; /* Size of the CS in dwords. */
44 };
45
46 enum r300_value_id {
47 R300_VID_PCI_ID,
48 R300_VID_GB_PIPES,
49 R300_VID_Z_PIPES,
50 R300_VID_SQUARE_TILING_SUPPORT,
51 R300_VID_DRM_2_3_0,
52 R300_VID_DRM_2_6_0,
53 R300_CAN_HYPERZ,
54 };
55
56 enum r300_reference_domain { /* bitfield */
57 R300_REF_CS = 1,
58 R300_REF_HW = 2
59 };
60
61 struct r300_winsys_screen {
62 /**
63 * Destroy this winsys.
64 *
65 * \param ws The winsys this function is called from.
66 */
67 void (*destroy)(struct r300_winsys_screen *ws);
68
69 /**
70 * Query a system value from a winsys.
71 *
72 * \param ws The winsys this function is called from.
73 * \param vid One of the R300_VID_* enums.
74 */
75 uint32_t (*get_value)(struct r300_winsys_screen *ws,
76 enum r300_value_id vid);
77
78 /**************************************************************************
79 * Buffer management. Buffer attributes are mostly fixed over its lifetime.
80 *
81 * Remember that gallium gets to choose the interface it needs, and the
82 * window systems must then implement that interface (rather than the
83 * other way around...).
84 *************************************************************************/
85
86 /**
87 * Create a buffer object.
88 *
89 * \param ws The winsys this function is called from.
90 * \param size The size to allocate.
91 * \param alignment An alignment of the buffer in memory.
92 * \param bind A bitmask of the PIPE_BIND_* flags.
93 * \param usage A bitmask of the PIPE_USAGE_* flags.
94 * \param domain A bitmask of the R300_DOMAIN_* flags.
95 * \return The created buffer object.
96 */
97 struct r300_winsys_buffer *(*buffer_create)(struct r300_winsys_screen *ws,
98 unsigned size,
99 unsigned alignment,
100 unsigned bind,
101 unsigned usage,
102 enum r300_buffer_domain domain);
103
104 /**
105 * Reference a buffer object (assign with reference counting).
106 *
107 * \param ws The winsys this function is called from.
108 * \param pdst A destination pointer to set the source buffer to.
109 * \param src A source buffer object.
110 */
111 void (*buffer_reference)(struct r300_winsys_screen *ws,
112 struct r300_winsys_buffer **pdst,
113 struct r300_winsys_buffer *src);
114
115 /**
116 * Map the entire data store of a buffer object into the client's address
117 * space.
118 *
119 * \param ws The winsys this function is called from.
120 * \param buf A winsys buffer object to map.
121 * \param cs A command stream to flush if the buffer is referenced by it.
122 * \param usage A bitmask of the PIPE_TRANSFER_* flags.
123 * \return The pointer at the beginning of the buffer.
124 */
125 void *(*buffer_map)(struct r300_winsys_screen *ws,
126 struct r300_winsys_buffer *buf,
127 struct r300_winsys_cs *cs,
128 enum pipe_transfer_usage usage);
129
130 /**
131 * Unmap a buffer object from the client's address space.
132 *
133 * \param ws The winsys this function is called from.
134 * \param buf A winsys buffer object to unmap.
135 */
136 void (*buffer_unmap)(struct r300_winsys_screen *ws,
137 struct r300_winsys_buffer *buf);
138
139 /**
140 * Wait for a buffer object until it is not used by a GPU. This is
141 * equivalent to a fence placed after the last command using the buffer,
142 * and synchronizing to the fence.
143 *
144 * \param ws The winsys this function is called from.
145 * \param buf A winsys buffer object to wait for.
146 */
147 void (*buffer_wait)(struct r300_winsys_screen *ws,
148 struct r300_winsys_buffer *buf);
149
150 /**
151 * Return tiling flags describing a memory layout of a buffer object.
152 *
153 * \param ws The winsys this function is called from.
154 * \param buf A winsys buffer object to get the flags from.
155 * \param macrotile A pointer to the return value of the microtile flag.
156 * \param microtile A pointer to the return value of the macrotile flag.
157 *
158 * \note microtile and macrotile are not bitmasks!
159 */
160 void (*buffer_get_tiling)(struct r300_winsys_screen *ws,
161 struct r300_winsys_buffer *buf,
162 enum r300_buffer_tiling *microtile,
163 enum r300_buffer_tiling *macrotile);
164
165 /**
166 * Set tiling flags describing a memory layout of a buffer object.
167 *
168 * \param ws The winsys this function is called from.
169 * \param buf A winsys buffer object to set the flags for.
170 * \param macrotile A macrotile flag.
171 * \param microtile A microtile flag.
172 * \param stride A stride of the buffer in bytes, for texturing.
173 *
174 * \note microtile and macrotile are not bitmasks!
175 */
176 void (*buffer_set_tiling)(struct r300_winsys_screen *ws,
177 struct r300_winsys_buffer *buf,
178 enum r300_buffer_tiling microtile,
179 enum r300_buffer_tiling macrotile,
180 unsigned stride);
181
182 /**
183 * Get a winsys buffer from a winsys handle. The internal structure
184 * of the handle is platform-specific and only a winsys should access it.
185 *
186 * \param ws The winsys this function is called from.
187 * \param whandle A winsys handle pointer as was received from a state
188 * tracker.
189 * \param stride The returned buffer stride in bytes.
190 * \param size The returned buffer size.
191 */
192 struct r300_winsys_buffer *(*buffer_from_handle)(struct r300_winsys_screen *ws,
193 struct winsys_handle *whandle,
194 unsigned *stride,
195 unsigned *size);
196
197 /**
198 * Get a winsys handle from a winsys buffer. The internal structure
199 * of the handle is platform-specific and only a winsys should access it.
200 *
201 * \param ws The winsys this function is called from.
202 * \param buf A winsys buffer object to get the handle from.
203 * \param whandle A winsys handle pointer.
204 * \param stride A stride of the buffer in bytes, for texturing.
205 * \return TRUE on success.
206 */
207 boolean (*buffer_get_handle)(struct r300_winsys_screen *ws,
208 struct r300_winsys_buffer *buf,
209 unsigned stride,
210 struct winsys_handle *whandle);
211
212 /**************************************************************************
213 * Command submission.
214 *
215 * Each pipe context should create its own command stream and submit
216 * commands independently of other contexts.
217 *************************************************************************/
218
219 /**
220 * Create a command stream.
221 *
222 * \param ws The winsys this function is called from.
223 */
224 struct r300_winsys_cs *(*cs_create)(struct r300_winsys_screen *ws);
225
226 /**
227 * Destroy a command stream.
228 *
229 * \param cs A command stream to destroy.
230 */
231 void (*cs_destroy)(struct r300_winsys_cs *cs);
232
233 /**
234 * Add a buffer object to the list of buffers to validate.
235 *
236 * \param cs A command stream to add buffer for validation against.
237 * \param buf A winsys buffer to validate.
238 * \param rd A read domain containing a bitmask
239 * of the R300_DOMAIN_* flags.
240 * \param wd A write domain containing a bitmask
241 * of the R300_DOMAIN_* flags.
242 */
243 void (*cs_add_buffer)(struct r300_winsys_cs *cs,
244 struct r300_winsys_buffer *buf,
245 enum r300_buffer_domain rd,
246 enum r300_buffer_domain wd);
247
248 /**
249 * Revalidate all currently set up winsys buffers.
250 * Returns TRUE if a flush is required.
251 *
252 * \param cs A command stream to validate.
253 */
254 boolean (*cs_validate)(struct r300_winsys_cs *cs);
255
256 /**
257 * Write a relocated dword to a command buffer.
258 *
259 * \param cs A command stream the relocation is written to.
260 * \param buf A winsys buffer to write the relocation for.
261 * \param rd A read domain containing a bitmask of the R300_DOMAIN_* flags.
262 * \param wd A write domain containing a bitmask of the R300_DOMAIN_* flags.
263 */
264 void (*cs_write_reloc)(struct r300_winsys_cs *cs,
265 struct r300_winsys_buffer *buf,
266 enum r300_buffer_domain rd,
267 enum r300_buffer_domain wd);
268
269 /**
270 * Flush a command stream.
271 *
272 * \param cs A command stream to flush.
273 */
274 void (*cs_flush)(struct r300_winsys_cs *cs);
275
276 /**
277 * Set a flush callback which is called from winsys when flush is
278 * required.
279 *
280 * \param cs A command stream to set the callback for.
281 * \param flush A flush callback function associated with the command stream.
282 * \param user A user pointer that will be passed to the flush callback.
283 */
284 void (*cs_set_flush)(struct r300_winsys_cs *cs,
285 void (*flush)(void *),
286 void *user);
287
288 /**
289 * Reset the list of buffer objects to validate, usually called
290 * prior to adding buffer objects for validation.
291 *
292 * \param cs A command stream to reset buffers for.
293 */
294 void (*cs_reset_buffers)(struct r300_winsys_cs *cs);
295
296 /**
297 * Return TRUE if a buffer is referenced by a command stream or by hardware
298 * (i.e. is busy), based on the domain parameter.
299 *
300 * \param cs A command stream.
301 * \param buf A winsys buffer.
302 * \param domain A bitmask of the R300_REF_* enums.
303 */
304 boolean (*cs_is_buffer_referenced)(struct r300_winsys_cs *cs,
305 struct r300_winsys_buffer *buf,
306 enum r300_reference_domain domain);
307 };
308
309 #endif /* R300_WINSYS_H */