i965/drm: s/drm_intel/drm_bacon/g
[mesa.git] / src / mesa / drivers / dri / i965 / intel_bufmgr.c
1 /*
2 * Copyright © 2007 Intel Corporation
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 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * 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 NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 * Authors:
24 * Eric Anholt <eric@anholt.net>
25 *
26 */
27
28 #ifdef HAVE_CONFIG_H
29 #include "config.h"
30 #endif
31
32 #include <string.h>
33 #include <stdlib.h>
34 #include <stdint.h>
35 #include <assert.h>
36 #include <errno.h>
37 #include <drm.h>
38 #include <i915_drm.h>
39 #include "libdrm_macros.h"
40 #include "intel_bufmgr.h"
41 #include "intel_bufmgr_priv.h"
42 #include "xf86drm.h"
43
44 /** @file intel_bufmgr.c
45 *
46 * Convenience functions for buffer management methods.
47 */
48
49 drm_bacon_bo *
50 drm_bacon_bo_alloc(drm_bacon_bufmgr *bufmgr, const char *name,
51 unsigned long size, unsigned int alignment)
52 {
53 return bufmgr->bo_alloc(bufmgr, name, size, alignment);
54 }
55
56 drm_bacon_bo *
57 drm_bacon_bo_alloc_for_render(drm_bacon_bufmgr *bufmgr, const char *name,
58 unsigned long size, unsigned int alignment)
59 {
60 return bufmgr->bo_alloc_for_render(bufmgr, name, size, alignment);
61 }
62
63 drm_bacon_bo *
64 drm_bacon_bo_alloc_userptr(drm_bacon_bufmgr *bufmgr,
65 const char *name, void *addr,
66 uint32_t tiling_mode,
67 uint32_t stride,
68 unsigned long size,
69 unsigned long flags)
70 {
71 if (bufmgr->bo_alloc_userptr)
72 return bufmgr->bo_alloc_userptr(bufmgr, name, addr, tiling_mode,
73 stride, size, flags);
74 return NULL;
75 }
76
77 drm_bacon_bo *
78 drm_bacon_bo_alloc_tiled(drm_bacon_bufmgr *bufmgr, const char *name,
79 int x, int y, int cpp, uint32_t *tiling_mode,
80 unsigned long *pitch, unsigned long flags)
81 {
82 return bufmgr->bo_alloc_tiled(bufmgr, name, x, y, cpp,
83 tiling_mode, pitch, flags);
84 }
85
86 void
87 drm_bacon_bo_reference(drm_bacon_bo *bo)
88 {
89 bo->bufmgr->bo_reference(bo);
90 }
91
92 void
93 drm_bacon_bo_unreference(drm_bacon_bo *bo)
94 {
95 if (bo == NULL)
96 return;
97
98 bo->bufmgr->bo_unreference(bo);
99 }
100
101 int
102 drm_bacon_bo_map(drm_bacon_bo *buf, int write_enable)
103 {
104 return buf->bufmgr->bo_map(buf, write_enable);
105 }
106
107 int
108 drm_bacon_bo_unmap(drm_bacon_bo *buf)
109 {
110 return buf->bufmgr->bo_unmap(buf);
111 }
112
113 int
114 drm_bacon_bo_subdata(drm_bacon_bo *bo, unsigned long offset,
115 unsigned long size, const void *data)
116 {
117 return bo->bufmgr->bo_subdata(bo, offset, size, data);
118 }
119
120 int
121 drm_bacon_bo_get_subdata(drm_bacon_bo *bo, unsigned long offset,
122 unsigned long size, void *data)
123 {
124 int ret;
125 if (bo->bufmgr->bo_get_subdata)
126 return bo->bufmgr->bo_get_subdata(bo, offset, size, data);
127
128 if (size == 0 || data == NULL)
129 return 0;
130
131 ret = drm_bacon_bo_map(bo, 0);
132 if (ret)
133 return ret;
134 memcpy(data, (unsigned char *)bo->virtual + offset, size);
135 drm_bacon_bo_unmap(bo);
136 return 0;
137 }
138
139 void
140 drm_bacon_bo_wait_rendering(drm_bacon_bo *bo)
141 {
142 bo->bufmgr->bo_wait_rendering(bo);
143 }
144
145 void
146 drm_bacon_bufmgr_destroy(drm_bacon_bufmgr *bufmgr)
147 {
148 bufmgr->destroy(bufmgr);
149 }
150
151 int
152 drm_bacon_bo_exec(drm_bacon_bo *bo, int used,
153 drm_clip_rect_t * cliprects, int num_cliprects, int DR4)
154 {
155 return bo->bufmgr->bo_exec(bo, used, cliprects, num_cliprects, DR4);
156 }
157
158 int
159 drm_bacon_bo_mrb_exec(drm_bacon_bo *bo, int used,
160 drm_clip_rect_t *cliprects, int num_cliprects, int DR4,
161 unsigned int rings)
162 {
163 if (bo->bufmgr->bo_mrb_exec)
164 return bo->bufmgr->bo_mrb_exec(bo, used,
165 cliprects, num_cliprects, DR4,
166 rings);
167
168 switch (rings) {
169 case I915_EXEC_DEFAULT:
170 case I915_EXEC_RENDER:
171 return bo->bufmgr->bo_exec(bo, used,
172 cliprects, num_cliprects, DR4);
173 default:
174 return -ENODEV;
175 }
176 }
177
178 void
179 drm_bacon_bufmgr_set_debug(drm_bacon_bufmgr *bufmgr, int enable_debug)
180 {
181 bufmgr->debug = enable_debug;
182 }
183
184 int
185 drm_bacon_bufmgr_check_aperture_space(drm_bacon_bo ** bo_array, int count)
186 {
187 return bo_array[0]->bufmgr->check_aperture_space(bo_array, count);
188 }
189
190 int
191 drm_bacon_bo_flink(drm_bacon_bo *bo, uint32_t * name)
192 {
193 if (bo->bufmgr->bo_flink)
194 return bo->bufmgr->bo_flink(bo, name);
195
196 return -ENODEV;
197 }
198
199 int
200 drm_bacon_bo_emit_reloc(drm_bacon_bo *bo, uint32_t offset,
201 drm_bacon_bo *target_bo, uint32_t target_offset,
202 uint32_t read_domains, uint32_t write_domain)
203 {
204 return bo->bufmgr->bo_emit_reloc(bo, offset,
205 target_bo, target_offset,
206 read_domains, write_domain);
207 }
208
209 /* For fence registers, not GL fences */
210 int
211 drm_bacon_bo_emit_reloc_fence(drm_bacon_bo *bo, uint32_t offset,
212 drm_bacon_bo *target_bo, uint32_t target_offset,
213 uint32_t read_domains, uint32_t write_domain)
214 {
215 return bo->bufmgr->bo_emit_reloc_fence(bo, offset,
216 target_bo, target_offset,
217 read_domains, write_domain);
218 }
219
220
221 int
222 drm_bacon_bo_pin(drm_bacon_bo *bo, uint32_t alignment)
223 {
224 if (bo->bufmgr->bo_pin)
225 return bo->bufmgr->bo_pin(bo, alignment);
226
227 return -ENODEV;
228 }
229
230 int
231 drm_bacon_bo_unpin(drm_bacon_bo *bo)
232 {
233 if (bo->bufmgr->bo_unpin)
234 return bo->bufmgr->bo_unpin(bo);
235
236 return -ENODEV;
237 }
238
239 int
240 drm_bacon_bo_set_tiling(drm_bacon_bo *bo, uint32_t * tiling_mode,
241 uint32_t stride)
242 {
243 if (bo->bufmgr->bo_set_tiling)
244 return bo->bufmgr->bo_set_tiling(bo, tiling_mode, stride);
245
246 *tiling_mode = I915_TILING_NONE;
247 return 0;
248 }
249
250 int
251 drm_bacon_bo_get_tiling(drm_bacon_bo *bo, uint32_t * tiling_mode,
252 uint32_t * swizzle_mode)
253 {
254 if (bo->bufmgr->bo_get_tiling)
255 return bo->bufmgr->bo_get_tiling(bo, tiling_mode, swizzle_mode);
256
257 *tiling_mode = I915_TILING_NONE;
258 *swizzle_mode = I915_BIT_6_SWIZZLE_NONE;
259 return 0;
260 }
261
262 int
263 drm_bacon_bo_set_softpin_offset(drm_bacon_bo *bo, uint64_t offset)
264 {
265 if (bo->bufmgr->bo_set_softpin_offset)
266 return bo->bufmgr->bo_set_softpin_offset(bo, offset);
267
268 return -ENODEV;
269 }
270
271 int
272 drm_bacon_bo_disable_reuse(drm_bacon_bo *bo)
273 {
274 if (bo->bufmgr->bo_disable_reuse)
275 return bo->bufmgr->bo_disable_reuse(bo);
276 return 0;
277 }
278
279 int
280 drm_bacon_bo_is_reusable(drm_bacon_bo *bo)
281 {
282 if (bo->bufmgr->bo_is_reusable)
283 return bo->bufmgr->bo_is_reusable(bo);
284 return 0;
285 }
286
287 int
288 drm_bacon_bo_busy(drm_bacon_bo *bo)
289 {
290 if (bo->bufmgr->bo_busy)
291 return bo->bufmgr->bo_busy(bo);
292 return 0;
293 }
294
295 int
296 drm_bacon_bo_madvise(drm_bacon_bo *bo, int madv)
297 {
298 if (bo->bufmgr->bo_madvise)
299 return bo->bufmgr->bo_madvise(bo, madv);
300 return -1;
301 }
302
303 int
304 drm_bacon_bo_use_48b_address_range(drm_bacon_bo *bo, uint32_t enable)
305 {
306 if (bo->bufmgr->bo_use_48b_address_range) {
307 bo->bufmgr->bo_use_48b_address_range(bo, enable);
308 return 0;
309 }
310
311 return -ENODEV;
312 }
313
314 int
315 drm_bacon_bo_references(drm_bacon_bo *bo, drm_bacon_bo *target_bo)
316 {
317 return bo->bufmgr->bo_references(bo, target_bo);
318 }
319
320 int
321 drm_bacon_get_pipe_from_crtc_id(drm_bacon_bufmgr *bufmgr, int crtc_id)
322 {
323 if (bufmgr->get_pipe_from_crtc_id)
324 return bufmgr->get_pipe_from_crtc_id(bufmgr, crtc_id);
325 return -1;
326 }