2 * Copyright © 2008 Jérôme Glisse
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sub license, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
14 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
15 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16 * NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS, AUTHORS
17 * AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 * USE OR OTHER DEALINGS IN THE SOFTWARE.
22 * The above copyright notice and this permission notice (including the
23 * next paragraph) shall be included in all copies or substantial portions
28 * Jérôme Glisse <glisse@freedesktop.org>
35 //#include "radeon_track.h"
38 #define RADEON_BO_FLAGS_MACRO_TILE 1
39 #define RADEON_BO_FLAGS_MICRO_TILE 2
41 struct radeon_bo_manager
;
50 #ifdef RADEON_BO_TRACK
51 struct radeon_track
*track
;
54 struct radeon_bo_manager
*bom
;
55 uint32_t space_accounted
;
59 struct radeon_bo_funcs
{
60 struct radeon_bo
*(*bo_open
)(struct radeon_bo_manager
*bom
,
66 void (*bo_ref
)(struct radeon_bo
*bo
);
67 struct radeon_bo
*(*bo_unref
)(struct radeon_bo
*bo
);
68 int (*bo_map
)(struct radeon_bo
*bo
, int write
);
69 int (*bo_unmap
)(struct radeon_bo
*bo
);
70 int (*bo_wait
)(struct radeon_bo
*bo
);
71 int (*bo_is_static
)(struct radeon_bo
*bo
);
72 int (*bo_set_tiling
)(struct radeon_bo
*bo
, uint32_t tiling_flags
,
74 int (*bo_get_tiling
)(struct radeon_bo
*bo
, uint32_t *tiling_flags
,
76 int (*bo_is_busy
)(struct radeon_bo
*bo
, uint32_t *domain
);
79 struct radeon_bo_manager
{
80 struct radeon_bo_funcs
*funcs
;
83 #ifdef RADEON_BO_TRACK
84 struct radeon_tracker tracker
;
88 static inline void _radeon_bo_debug(struct radeon_bo
*bo
,
94 fprintf(stderr
, "%s %p 0x%08X 0x%08X 0x%08X [%s %s %d]\n",
95 op
, bo
, bo
->handle
, bo
->size
, bo
->cref
, file
, func
, line
);
98 static inline struct radeon_bo
*_radeon_bo_open(struct radeon_bo_manager
*bom
,
108 struct radeon_bo
*bo
;
110 bo
= bom
->funcs
->bo_open(bom
, handle
, size
, alignment
, domains
, flags
);
112 #ifdef RADEON_BO_TRACK
114 bo
->track
= radeon_tracker_add_track(&bom
->tracker
, bo
->handle
);
115 radeon_track_add_event(bo
->track
, file
, func
, "open", line
);
121 static inline void _radeon_bo_ref(struct radeon_bo
*bo
,
127 #ifdef RADEON_BO_TRACK
128 radeon_track_add_event(bo
->track
, file
, func
, "ref", line
);
130 bo
->bom
->funcs
->bo_ref(bo
);
133 static inline struct radeon_bo
*_radeon_bo_unref(struct radeon_bo
*bo
,
139 #ifdef RADEON_BO_TRACK
140 radeon_track_add_event(bo
->track
, file
, func
, "unref", line
);
142 radeon_tracker_remove_track(&bo
->bom
->tracker
, bo
->track
);
146 return bo
->bom
->funcs
->bo_unref(bo
);
149 static inline int _radeon_bo_map(struct radeon_bo
*bo
,
155 return bo
->bom
->funcs
->bo_map(bo
, write
);
158 static inline int _radeon_bo_unmap(struct radeon_bo
*bo
,
163 return bo
->bom
->funcs
->bo_unmap(bo
);
166 static inline int _radeon_bo_wait(struct radeon_bo
*bo
,
171 return bo
->bom
->funcs
->bo_wait(bo
);
174 static inline int _radeon_bo_is_busy(struct radeon_bo
*bo
,
180 return bo
->bom
->funcs
->bo_is_busy(bo
, domain
);
183 static inline int radeon_bo_set_tiling(struct radeon_bo
*bo
,
184 uint32_t tiling_flags
, uint32_t pitch
)
186 return bo
->bom
->funcs
->bo_set_tiling(bo
, tiling_flags
, pitch
);
189 static inline int radeon_bo_get_tiling(struct radeon_bo
*bo
,
190 uint32_t *tiling_flags
, uint32_t *pitch
)
192 return bo
->bom
->funcs
->bo_get_tiling(bo
, tiling_flags
, pitch
);
195 static inline int radeon_bo_is_static(struct radeon_bo
*bo
)
197 if (bo
->bom
->funcs
->bo_is_static
)
198 return bo
->bom
->funcs
->bo_is_static(bo
);
202 #define radeon_bo_open(bom, h, s, a, d, f)\
203 _radeon_bo_open(bom, h, s, a, d, f, __FILE__, __FUNCTION__, __LINE__)
204 #define radeon_bo_ref(bo)\
205 _radeon_bo_ref(bo, __FILE__, __FUNCTION__, __LINE__)
206 #define radeon_bo_unref(bo)\
207 _radeon_bo_unref(bo, __FILE__, __FUNCTION__, __LINE__)
208 #define radeon_bo_map(bo, w)\
209 _radeon_bo_map(bo, w, __FILE__, __FUNCTION__, __LINE__)
210 #define radeon_bo_unmap(bo)\
211 _radeon_bo_unmap(bo, __FILE__, __FUNCTION__, __LINE__)
212 #define radeon_bo_debug(bo, opcode)\
213 _radeon_bo_debug(bo, opcode, __FILE__, __FUNCTION__, __LINE__)
214 #define radeon_bo_wait(bo) \
215 _radeon_bo_wait(bo, __FILE__, __func__, __LINE__)
216 #define radeon_bo_is_busy(bo, domain) \
217 _radeon_bo_is_busy(bo, domain, __FILE__, __func__, __LINE__)