i965/drm: Check INTEL_DEBUG & DEBUG_BUFMGR directly.
[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 "brw_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 int
179 drm_bacon_bufmgr_check_aperture_space(drm_bacon_bo ** bo_array, int count)
180 {
181 return bo_array[0]->bufmgr->check_aperture_space(bo_array, count);
182 }
183
184 int
185 drm_bacon_bo_flink(drm_bacon_bo *bo, uint32_t * name)
186 {
187 if (bo->bufmgr->bo_flink)
188 return bo->bufmgr->bo_flink(bo, name);
189
190 return -ENODEV;
191 }
192
193 int
194 drm_bacon_bo_emit_reloc(drm_bacon_bo *bo, uint32_t offset,
195 drm_bacon_bo *target_bo, uint32_t target_offset,
196 uint32_t read_domains, uint32_t write_domain)
197 {
198 return bo->bufmgr->bo_emit_reloc(bo, offset,
199 target_bo, target_offset,
200 read_domains, write_domain);
201 }
202
203 int
204 drm_bacon_bo_set_tiling(drm_bacon_bo *bo, uint32_t * tiling_mode,
205 uint32_t stride)
206 {
207 if (bo->bufmgr->bo_set_tiling)
208 return bo->bufmgr->bo_set_tiling(bo, tiling_mode, stride);
209
210 *tiling_mode = I915_TILING_NONE;
211 return 0;
212 }
213
214 int
215 drm_bacon_bo_get_tiling(drm_bacon_bo *bo, uint32_t * tiling_mode,
216 uint32_t * swizzle_mode)
217 {
218 if (bo->bufmgr->bo_get_tiling)
219 return bo->bufmgr->bo_get_tiling(bo, tiling_mode, swizzle_mode);
220
221 *tiling_mode = I915_TILING_NONE;
222 *swizzle_mode = I915_BIT_6_SWIZZLE_NONE;
223 return 0;
224 }
225
226 int
227 drm_bacon_bo_set_softpin_offset(drm_bacon_bo *bo, uint64_t offset)
228 {
229 if (bo->bufmgr->bo_set_softpin_offset)
230 return bo->bufmgr->bo_set_softpin_offset(bo, offset);
231
232 return -ENODEV;
233 }
234
235 int
236 drm_bacon_bo_disable_reuse(drm_bacon_bo *bo)
237 {
238 if (bo->bufmgr->bo_disable_reuse)
239 return bo->bufmgr->bo_disable_reuse(bo);
240 return 0;
241 }
242
243 int
244 drm_bacon_bo_is_reusable(drm_bacon_bo *bo)
245 {
246 if (bo->bufmgr->bo_is_reusable)
247 return bo->bufmgr->bo_is_reusable(bo);
248 return 0;
249 }
250
251 int
252 drm_bacon_bo_busy(drm_bacon_bo *bo)
253 {
254 if (bo->bufmgr->bo_busy)
255 return bo->bufmgr->bo_busy(bo);
256 return 0;
257 }
258
259 int
260 drm_bacon_bo_madvise(drm_bacon_bo *bo, int madv)
261 {
262 if (bo->bufmgr->bo_madvise)
263 return bo->bufmgr->bo_madvise(bo, madv);
264 return -1;
265 }
266
267 int
268 drm_bacon_bo_references(drm_bacon_bo *bo, drm_bacon_bo *target_bo)
269 {
270 return bo->bufmgr->bo_references(bo, target_bo);
271 }