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 "brw_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_check_aperture_space(drm_bacon_bo
** bo_array
, int count
)
181 return bo_array
[0]->bufmgr
->check_aperture_space(bo_array
, count
);
185 drm_bacon_bo_flink(drm_bacon_bo
*bo
, uint32_t * name
)
187 if (bo
->bufmgr
->bo_flink
)
188 return bo
->bufmgr
->bo_flink(bo
, name
);
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
)
198 return bo
->bufmgr
->bo_emit_reloc(bo
, offset
,
199 target_bo
, target_offset
,
200 read_domains
, write_domain
);
204 drm_bacon_bo_set_tiling(drm_bacon_bo
*bo
, uint32_t * tiling_mode
,
207 if (bo
->bufmgr
->bo_set_tiling
)
208 return bo
->bufmgr
->bo_set_tiling(bo
, tiling_mode
, stride
);
210 *tiling_mode
= I915_TILING_NONE
;
215 drm_bacon_bo_get_tiling(drm_bacon_bo
*bo
, uint32_t * tiling_mode
,
216 uint32_t * swizzle_mode
)
218 if (bo
->bufmgr
->bo_get_tiling
)
219 return bo
->bufmgr
->bo_get_tiling(bo
, tiling_mode
, swizzle_mode
);
221 *tiling_mode
= I915_TILING_NONE
;
222 *swizzle_mode
= I915_BIT_6_SWIZZLE_NONE
;
227 drm_bacon_bo_set_softpin_offset(drm_bacon_bo
*bo
, uint64_t offset
)
229 if (bo
->bufmgr
->bo_set_softpin_offset
)
230 return bo
->bufmgr
->bo_set_softpin_offset(bo
, offset
);
236 drm_bacon_bo_disable_reuse(drm_bacon_bo
*bo
)
238 if (bo
->bufmgr
->bo_disable_reuse
)
239 return bo
->bufmgr
->bo_disable_reuse(bo
);
244 drm_bacon_bo_is_reusable(drm_bacon_bo
*bo
)
246 if (bo
->bufmgr
->bo_is_reusable
)
247 return bo
->bufmgr
->bo_is_reusable(bo
);
252 drm_bacon_bo_busy(drm_bacon_bo
*bo
)
254 if (bo
->bufmgr
->bo_busy
)
255 return bo
->bufmgr
->bo_busy(bo
);
260 drm_bacon_bo_madvise(drm_bacon_bo
*bo
, int madv
)
262 if (bo
->bufmgr
->bo_madvise
)
263 return bo
->bufmgr
->bo_madvise(bo
, madv
);
268 drm_bacon_bo_references(drm_bacon_bo
*bo
, drm_bacon_bo
*target_bo
)
270 return bo
->bufmgr
->bo_references(bo
, target_bo
);