Merge branch 'arb_map_buffer_range'
[mesa.git] / src / mesa / drivers / dri / radeon / radeon_cs_drm.h
1 /*
2 * Copyright © 2008 Nicolai Haehnle
3 * Copyright © 2008 Jérôme Glisse
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
18 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19 * OTHERWISE, 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 * Aapo Tahkola <aet@rasterburn.org>
29 * Nicolai Haehnle <prefect_@gmx.net>
30 * Jérôme Glisse <glisse@freedesktop.org>
31 */
32 #ifndef RADEON_CS_H
33 #define RADEON_CS_H
34
35 #include <stdint.h>
36 #include <string.h>
37 #include "drm.h"
38 #include "radeon_drm.h"
39
40 struct radeon_cs_reloc {
41 struct radeon_bo *bo;
42 uint32_t read_domain;
43 uint32_t write_domain;
44 uint32_t flags;
45 };
46
47
48 #define RADEON_CS_SPACE_OK 0
49 #define RADEON_CS_SPACE_OP_TO_BIG 1
50 #define RADEON_CS_SPACE_FLUSH 2
51
52 struct radeon_cs_space_check {
53 struct radeon_bo *bo;
54 uint32_t read_domains;
55 uint32_t write_domain;
56 uint32_t new_accounted;
57 };
58
59 struct radeon_cs_manager;
60
61 struct radeon_cs {
62 struct radeon_cs_manager *csm;
63 void *relocs;
64 uint32_t *packets;
65 unsigned crelocs;
66 unsigned relocs_total_size;
67 unsigned cdw;
68 unsigned ndw;
69 int section;
70 unsigned section_ndw;
71 unsigned section_cdw;
72 const char *section_file;
73 const char *section_func;
74 int section_line;
75
76 };
77
78 /* cs functions */
79 struct radeon_cs_funcs {
80 struct radeon_cs *(*cs_create)(struct radeon_cs_manager *csm,
81 uint32_t ndw);
82 int (*cs_write_reloc)(struct radeon_cs *cs,
83 struct radeon_bo *bo,
84 uint32_t read_domain,
85 uint32_t write_domain,
86 uint32_t flags);
87 int (*cs_begin)(struct radeon_cs *cs,
88 uint32_t ndw,
89 const char *file,
90 const char *func,
91 int line);
92 int (*cs_end)(struct radeon_cs *cs,
93 const char *file,
94 const char *func,
95 int line);
96 int (*cs_emit)(struct radeon_cs *cs);
97 int (*cs_destroy)(struct radeon_cs *cs);
98 int (*cs_erase)(struct radeon_cs *cs);
99 int (*cs_need_flush)(struct radeon_cs *cs);
100 void (*cs_print)(struct radeon_cs *cs, FILE *file);
101 int (*cs_space_check)(struct radeon_cs *cs, struct radeon_cs_space_check *bos,
102 int num_bo);
103 };
104
105 struct radeon_cs_manager {
106 struct radeon_cs_funcs *funcs;
107 int fd;
108 uint32_t vram_limit, gart_limit;
109 uint32_t vram_write_used, gart_write_used;
110 uint32_t read_used;
111 };
112
113 static inline struct radeon_cs *radeon_cs_create(struct radeon_cs_manager *csm,
114 uint32_t ndw)
115 {
116 return csm->funcs->cs_create(csm, ndw);
117 }
118
119 static inline int radeon_cs_write_reloc(struct radeon_cs *cs,
120 struct radeon_bo *bo,
121 uint32_t read_domain,
122 uint32_t write_domain,
123 uint32_t flags)
124 {
125 return cs->csm->funcs->cs_write_reloc(cs,
126 bo,
127 read_domain,
128 write_domain,
129 flags);
130 }
131
132 static inline int radeon_cs_begin(struct radeon_cs *cs,
133 uint32_t ndw,
134 const char *file,
135 const char *func,
136 int line)
137 {
138 return cs->csm->funcs->cs_begin(cs, ndw, file, func, line);
139 }
140
141 static inline int radeon_cs_end(struct radeon_cs *cs,
142 const char *file,
143 const char *func,
144 int line)
145 {
146 return cs->csm->funcs->cs_end(cs, file, func, line);
147 }
148
149 static inline int radeon_cs_emit(struct radeon_cs *cs)
150 {
151 return cs->csm->funcs->cs_emit(cs);
152 }
153
154 static inline int radeon_cs_destroy(struct radeon_cs *cs)
155 {
156 return cs->csm->funcs->cs_destroy(cs);
157 }
158
159 static inline int radeon_cs_erase(struct radeon_cs *cs)
160 {
161 return cs->csm->funcs->cs_erase(cs);
162 }
163
164 static inline int radeon_cs_need_flush(struct radeon_cs *cs)
165 {
166 return cs->csm->funcs->cs_need_flush(cs);
167 }
168
169 static inline void radeon_cs_print(struct radeon_cs *cs, FILE *file)
170 {
171 cs->csm->funcs->cs_print(cs, file);
172 }
173
174 static inline int radeon_cs_space_check(struct radeon_cs *cs,
175 struct radeon_cs_space_check *bos,
176 int num_bo)
177 {
178 return cs->csm->funcs->cs_space_check(cs, bos, num_bo);
179 }
180
181 static inline void radeon_cs_set_limit(struct radeon_cs *cs, uint32_t domain, uint32_t limit)
182 {
183
184 if (domain == RADEON_GEM_DOMAIN_VRAM)
185 cs->csm->vram_limit = limit;
186 else
187 cs->csm->gart_limit = limit;
188 }
189
190 static inline void radeon_cs_write_dword(struct radeon_cs *cs, uint32_t dword)
191 {
192 cs->packets[cs->cdw++] = dword;
193 if (cs->section) {
194 cs->section_cdw++;
195 }
196 }
197
198 static inline void radeon_cs_write_qword(struct radeon_cs *cs, uint64_t qword)
199 {
200
201 memcpy(cs->packets + cs->cdw, &qword, sizeof(qword));
202 cs->cdw+=2;
203 if (cs->section) {
204 cs->section_cdw+=2;
205 }
206 }
207 #endif