2 * Copyright © 2007 Intel Corporation
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:
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
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
24 * Eric Anholt <eric@anholt.net>
39 #include "libdrm_macros.h"
40 #include "intel_bufmgr.h"
41 #include "intel_bufmgr_priv.h"
44 /** @file intel_bufmgr.c
46 * Convenience functions for buffer management methods.
50 drm_bacon_bo_alloc(drm_bacon_bufmgr
*bufmgr
, const char *name
,
51 unsigned long size
, unsigned int alignment
)
53 return bufmgr
->bo_alloc(bufmgr
, name
, size
, alignment
);
57 drm_bacon_bo_alloc_for_render(drm_bacon_bufmgr
*bufmgr
, const char *name
,
58 unsigned long size
, unsigned int alignment
)
60 return bufmgr
->bo_alloc_for_render(bufmgr
, name
, size
, alignment
);
64 drm_bacon_bo_alloc_userptr(drm_bacon_bufmgr
*bufmgr
,
65 const char *name
, void *addr
,
71 if (bufmgr
->bo_alloc_userptr
)
72 return bufmgr
->bo_alloc_userptr(bufmgr
, name
, addr
, tiling_mode
,
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
)
82 return bufmgr
->bo_alloc_tiled(bufmgr
, name
, x
, y
, cpp
,
83 tiling_mode
, pitch
, flags
);
87 drm_bacon_bo_reference(drm_bacon_bo
*bo
)
89 bo
->bufmgr
->bo_reference(bo
);
93 drm_bacon_bo_unreference(drm_bacon_bo
*bo
)
98 bo
->bufmgr
->bo_unreference(bo
);
102 drm_bacon_bo_map(drm_bacon_bo
*buf
, int write_enable
)
104 return buf
->bufmgr
->bo_map(buf
, write_enable
);
108 drm_bacon_bo_unmap(drm_bacon_bo
*buf
)
110 return buf
->bufmgr
->bo_unmap(buf
);
114 drm_bacon_bo_subdata(drm_bacon_bo
*bo
, unsigned long offset
,
115 unsigned long size
, const void *data
)
117 return bo
->bufmgr
->bo_subdata(bo
, offset
, size
, data
);
121 drm_bacon_bo_get_subdata(drm_bacon_bo
*bo
, unsigned long offset
,
122 unsigned long size
, void *data
)
125 if (bo
->bufmgr
->bo_get_subdata
)
126 return bo
->bufmgr
->bo_get_subdata(bo
, offset
, size
, data
);
128 if (size
== 0 || data
== NULL
)
131 ret
= drm_bacon_bo_map(bo
, 0);
134 memcpy(data
, (unsigned char *)bo
->virtual + offset
, size
);
135 drm_bacon_bo_unmap(bo
);
140 drm_bacon_bo_wait_rendering(drm_bacon_bo
*bo
)
142 bo
->bufmgr
->bo_wait_rendering(bo
);
146 drm_bacon_bufmgr_destroy(drm_bacon_bufmgr
*bufmgr
)
148 bufmgr
->destroy(bufmgr
);
152 drm_bacon_bo_exec(drm_bacon_bo
*bo
, int used
,
153 drm_clip_rect_t
* cliprects
, int num_cliprects
, int DR4
)
155 return bo
->bufmgr
->bo_exec(bo
, used
, cliprects
, num_cliprects
, DR4
);
159 drm_bacon_bo_mrb_exec(drm_bacon_bo
*bo
, int used
,
160 drm_clip_rect_t
*cliprects
, int num_cliprects
, int DR4
,
163 if (bo
->bufmgr
->bo_mrb_exec
)
164 return bo
->bufmgr
->bo_mrb_exec(bo
, used
,
165 cliprects
, num_cliprects
, DR4
,
169 case I915_EXEC_DEFAULT
:
170 case I915_EXEC_RENDER
:
171 return bo
->bufmgr
->bo_exec(bo
, used
,
172 cliprects
, num_cliprects
, DR4
);
179 drm_bacon_bufmgr_set_debug(drm_bacon_bufmgr
*bufmgr
, int enable_debug
)
181 bufmgr
->debug
= enable_debug
;
185 drm_bacon_bufmgr_check_aperture_space(drm_bacon_bo
** bo_array
, int count
)
187 return bo_array
[0]->bufmgr
->check_aperture_space(bo_array
, count
);
191 drm_bacon_bo_flink(drm_bacon_bo
*bo
, uint32_t * name
)
193 if (bo
->bufmgr
->bo_flink
)
194 return bo
->bufmgr
->bo_flink(bo
, name
);
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
)
204 return bo
->bufmgr
->bo_emit_reloc(bo
, offset
,
205 target_bo
, target_offset
,
206 read_domains
, write_domain
);
209 /* For fence registers, not GL fences */
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
)
215 return bo
->bufmgr
->bo_emit_reloc_fence(bo
, offset
,
216 target_bo
, target_offset
,
217 read_domains
, write_domain
);
222 drm_bacon_bo_pin(drm_bacon_bo
*bo
, uint32_t alignment
)
224 if (bo
->bufmgr
->bo_pin
)
225 return bo
->bufmgr
->bo_pin(bo
, alignment
);
231 drm_bacon_bo_unpin(drm_bacon_bo
*bo
)
233 if (bo
->bufmgr
->bo_unpin
)
234 return bo
->bufmgr
->bo_unpin(bo
);
240 drm_bacon_bo_set_tiling(drm_bacon_bo
*bo
, uint32_t * tiling_mode
,
243 if (bo
->bufmgr
->bo_set_tiling
)
244 return bo
->bufmgr
->bo_set_tiling(bo
, tiling_mode
, stride
);
246 *tiling_mode
= I915_TILING_NONE
;
251 drm_bacon_bo_get_tiling(drm_bacon_bo
*bo
, uint32_t * tiling_mode
,
252 uint32_t * swizzle_mode
)
254 if (bo
->bufmgr
->bo_get_tiling
)
255 return bo
->bufmgr
->bo_get_tiling(bo
, tiling_mode
, swizzle_mode
);
257 *tiling_mode
= I915_TILING_NONE
;
258 *swizzle_mode
= I915_BIT_6_SWIZZLE_NONE
;
263 drm_bacon_bo_set_softpin_offset(drm_bacon_bo
*bo
, uint64_t offset
)
265 if (bo
->bufmgr
->bo_set_softpin_offset
)
266 return bo
->bufmgr
->bo_set_softpin_offset(bo
, offset
);
272 drm_bacon_bo_disable_reuse(drm_bacon_bo
*bo
)
274 if (bo
->bufmgr
->bo_disable_reuse
)
275 return bo
->bufmgr
->bo_disable_reuse(bo
);
280 drm_bacon_bo_is_reusable(drm_bacon_bo
*bo
)
282 if (bo
->bufmgr
->bo_is_reusable
)
283 return bo
->bufmgr
->bo_is_reusable(bo
);
288 drm_bacon_bo_busy(drm_bacon_bo
*bo
)
290 if (bo
->bufmgr
->bo_busy
)
291 return bo
->bufmgr
->bo_busy(bo
);
296 drm_bacon_bo_madvise(drm_bacon_bo
*bo
, int madv
)
298 if (bo
->bufmgr
->bo_madvise
)
299 return bo
->bufmgr
->bo_madvise(bo
, madv
);
304 drm_bacon_bo_use_48b_address_range(drm_bacon_bo
*bo
, uint32_t enable
)
306 if (bo
->bufmgr
->bo_use_48b_address_range
) {
307 bo
->bufmgr
->bo_use_48b_address_range(bo
, enable
);
315 drm_bacon_bo_references(drm_bacon_bo
*bo
, drm_bacon_bo
*target_bo
)
317 return bo
->bufmgr
->bo_references(bo
, target_bo
);
321 drm_bacon_get_pipe_from_crtc_id(drm_bacon_bufmgr
*bufmgr
, int crtc_id
)
323 if (bufmgr
->get_pipe_from_crtc_id
)
324 return bufmgr
->get_pipe_from_crtc_id(bufmgr
, crtc_id
);