Merge branch 'mesa_7_5_branch'
[mesa.git] / src / mesa / drivers / dri / radeon / radeon_bo_drm.h
1 /*
2 * Copyright © 2008 Jérôme Glisse
3 * All Rights Reserved.
4 *
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:
12 *
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.
21 *
22 * The above copyright notice and this permission notice (including the
23 * next paragraph) shall be included in all copies or substantial portions
24 * of the Software.
25 */
26 /*
27 * Authors:
28 * Jérôme Glisse <glisse@freedesktop.org>
29 */
30 #ifndef RADEON_BO_H
31 #define RADEON_BO_H
32
33 #include <stdio.h>
34 #include <stdint.h>
35 //#include "radeon_track.h"
36
37 /* bo object */
38 #define RADEON_BO_FLAGS_MACRO_TILE 1
39 #define RADEON_BO_FLAGS_MICRO_TILE 2
40
41 struct radeon_bo_manager;
42
43 struct radeon_bo {
44 uint32_t alignment;
45 uint32_t handle;
46 uint32_t size;
47 uint32_t domains;
48 uint32_t flags;
49 unsigned cref;
50 #ifdef RADEON_BO_TRACK
51 struct radeon_track *track;
52 #endif
53 void *ptr;
54 struct radeon_bo_manager *bom;
55 uint32_t space_accounted;
56 };
57
58 /* bo functions */
59 struct radeon_bo_funcs {
60 struct radeon_bo *(*bo_open)(struct radeon_bo_manager *bom,
61 uint32_t handle,
62 uint32_t size,
63 uint32_t alignment,
64 uint32_t domains,
65 uint32_t flags);
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 };
72
73 struct radeon_bo_manager {
74 struct radeon_bo_funcs *funcs;
75 int fd;
76
77 #ifdef RADEON_BO_TRACK
78 struct radeon_tracker tracker;
79 #endif
80 };
81
82 static inline void _radeon_bo_debug(struct radeon_bo *bo,
83 const char *op,
84 const char *file,
85 const char *func,
86 int line)
87 {
88 fprintf(stderr, "%s %p 0x%08X 0x%08X 0x%08X [%s %s %d]\n",
89 op, bo, bo->handle, bo->size, bo->cref, file, func, line);
90 }
91
92 static inline struct radeon_bo *_radeon_bo_open(struct radeon_bo_manager *bom,
93 uint32_t handle,
94 uint32_t size,
95 uint32_t alignment,
96 uint32_t domains,
97 uint32_t flags,
98 const char *file,
99 const char *func,
100 int line)
101 {
102 struct radeon_bo *bo;
103
104 bo = bom->funcs->bo_open(bom, handle, size, alignment, domains, flags);
105 #ifdef RADEON_BO_TRACK
106 if (bo) {
107 bo->track = radeon_tracker_add_track(&bom->tracker, bo->handle);
108 radeon_track_add_event(bo->track, file, func, "open", line);
109 }
110 #endif
111 return bo;
112 }
113
114 static inline void _radeon_bo_ref(struct radeon_bo *bo,
115 const char *file,
116 const char *func,
117 int line)
118 {
119 bo->cref++;
120 #ifdef RADEON_BO_TRACK
121 radeon_track_add_event(bo->track, file, func, "ref", line);
122 #endif
123 bo->bom->funcs->bo_ref(bo);
124 }
125
126 static inline struct radeon_bo *_radeon_bo_unref(struct radeon_bo *bo,
127 const char *file,
128 const char *func,
129 int line)
130 {
131 bo->cref--;
132 #ifdef RADEON_BO_TRACK
133 radeon_track_add_event(bo->track, file, func, "unref", line);
134 if (bo->cref <= 0) {
135 radeon_tracker_remove_track(&bo->bom->tracker, bo->track);
136 bo->track = NULL;
137 }
138 #endif
139 return bo->bom->funcs->bo_unref(bo);
140 }
141
142 static inline int _radeon_bo_map(struct radeon_bo *bo,
143 int write,
144 const char *file,
145 const char *func,
146 int line)
147 {
148 return bo->bom->funcs->bo_map(bo, write);
149 }
150
151 static inline int _radeon_bo_unmap(struct radeon_bo *bo,
152 const char *file,
153 const char *func,
154 int line)
155 {
156 return bo->bom->funcs->bo_unmap(bo);
157 }
158
159 static inline int _radeon_bo_wait(struct radeon_bo *bo,
160 const char *file,
161 const char *func,
162 int line)
163 {
164 return bo->bom->funcs->bo_wait(bo);
165 }
166
167 #define radeon_bo_open(bom, h, s, a, d, f)\
168 _radeon_bo_open(bom, h, s, a, d, f, __FILE__, __FUNCTION__, __LINE__)
169 #define radeon_bo_ref(bo)\
170 _radeon_bo_ref(bo, __FILE__, __FUNCTION__, __LINE__)
171 #define radeon_bo_unref(bo)\
172 _radeon_bo_unref(bo, __FILE__, __FUNCTION__, __LINE__)
173 #define radeon_bo_map(bo, w)\
174 _radeon_bo_map(bo, w, __FILE__, __FUNCTION__, __LINE__)
175 #define radeon_bo_unmap(bo)\
176 _radeon_bo_unmap(bo, __FILE__, __FUNCTION__, __LINE__)
177 #define radeon_bo_debug(bo, opcode)\
178 _radeon_bo_debug(bo, opcode, __FILE__, __FUNCTION__, __LINE__)
179 #define radeon_bo_wait(bo) \
180 _radeon_bo_wait(bo, __FILE__, __func__, __LINE__)
181
182 #endif