aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Airlie2009-06-17 02:47:42 -0500
committerDave Airlie2009-06-17 02:47:42 -0500
commit2fa2db138ba989bfa1a8cd9ab66d83fb7369249e (patch)
tree007e9806f4a439a7543f68fab51a13615d4ba15b /libdrm/radeon/radeon_bo.h
parent3d4bfe8c893d016ef43d1ebf28e4607aa1f540a4 (diff)
downloadexternal-libgbm-2fa2db138ba989bfa1a8cd9ab66d83fb7369249e.tar.gz
external-libgbm-2fa2db138ba989bfa1a8cd9ab66d83fb7369249e.tar.xz
external-libgbm-2fa2db138ba989bfa1a8cd9ab66d83fb7369249e.zip
libdrm/radeon: add initial libdrm_radeon
requires --enable-radeon-experimental-api for now
Diffstat (limited to 'libdrm/radeon/radeon_bo.h')
-rw-r--r--libdrm/radeon/radeon_bo.h179
1 files changed, 179 insertions, 0 deletions
diff --git a/libdrm/radeon/radeon_bo.h b/libdrm/radeon/radeon_bo.h
new file mode 100644
index 00000000..3cabdfc4
--- /dev/null
+++ b/libdrm/radeon/radeon_bo.h
@@ -0,0 +1,179 @@
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
41struct radeon_bo_manager;
42
43struct 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 */
59struct 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
73struct radeon_bo_manager {
74 struct radeon_bo_funcs *funcs;
75 int fd;
76 struct radeon_tracker tracker;
77};
78
79static inline void _radeon_bo_debug(struct radeon_bo *bo,
80 const char *op,
81 const char *file,
82 const char *func,
83 int line)
84{
85 fprintf(stderr, "%s %p 0x%08X 0x%08X 0x%08X [%s %s %d]\n",
86 op, bo, bo->handle, bo->size, bo->cref, file, func, line);
87}
88
89static inline struct radeon_bo *_radeon_bo_open(struct radeon_bo_manager *bom,
90 uint32_t handle,
91 uint32_t size,
92 uint32_t alignment,
93 uint32_t domains,
94 uint32_t flags,
95 const char *file,
96 const char *func,
97 int line)
98{
99 struct radeon_bo *bo;
100
101 bo = bom->funcs->bo_open(bom, handle, size, alignment, domains, flags);
102#ifdef RADEON_BO_TRACK
103 if (bo) {
104 bo->track = radeon_tracker_add_track(&bom->tracker, bo->handle);
105 radeon_track_add_event(bo->track, file, func, "open", line);
106 }
107#endif
108 return bo;
109}
110
111static inline void _radeon_bo_ref(struct radeon_bo *bo,
112 const char *file,
113 const char *func,
114 int line)
115{
116 bo->cref++;
117#ifdef RADEON_BO_TRACK
118 radeon_track_add_event(bo->track, file, func, "ref", line);
119#endif
120 bo->bom->funcs->bo_ref(bo);
121}
122
123static inline struct radeon_bo *_radeon_bo_unref(struct radeon_bo *bo,
124 const char *file,
125 const char *func,
126 int line)
127{
128 bo->cref--;
129#ifdef RADEON_BO_TRACK
130 radeon_track_add_event(bo->track, file, func, "unref", line);
131 if (bo->cref <= 0) {
132 radeon_tracker_remove_track(&bo->bom->tracker, bo->track);
133 bo->track = NULL;
134 }
135#endif
136 return bo->bom->funcs->bo_unref(bo);
137}
138
139static inline int _radeon_bo_map(struct radeon_bo *bo,
140 int write,
141 const char *file,
142 const char *func,
143 int line)
144{
145 return bo->bom->funcs->bo_map(bo, write);
146}
147
148static inline int _radeon_bo_unmap(struct radeon_bo *bo,
149 const char *file,
150 const char *func,
151 int line)
152{
153 return bo->bom->funcs->bo_unmap(bo);
154}
155
156static inline int _radeon_bo_wait(struct radeon_bo *bo,
157 const char *file,
158 const char *func,
159 int line)
160{
161 return bo->bom->funcs->bo_wait(bo);
162}
163
164#define radeon_bo_open(bom, h, s, a, d, f)\
165 _radeon_bo_open(bom, h, s, a, d, f, __FILE__, __FUNCTION__, __LINE__)
166#define radeon_bo_ref(bo)\
167 _radeon_bo_ref(bo, __FILE__, __FUNCTION__, __LINE__)
168#define radeon_bo_unref(bo)\
169 _radeon_bo_unref(bo, __FILE__, __FUNCTION__, __LINE__)
170#define radeon_bo_map(bo, w)\
171 _radeon_bo_map(bo, w, __FILE__, __FUNCTION__, __LINE__)
172#define radeon_bo_unmap(bo)\
173 _radeon_bo_unmap(bo, __FILE__, __FUNCTION__, __LINE__)
174#define radeon_bo_debug(bo, opcode)\
175 _radeon_bo_debug(bo, opcode, __FILE__, __FUNCTION__, __LINE__)
176#define radeon_bo_wait(bo) \
177 _radeon_bo_wait(bo, __FILE__, __func__, __LINE__)
178
179#endif