8f0b449e41f10ffed8dce03ffdadbf2d5ac15314
[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 "drm.h"
37 #include "radeon_drm.h"
38
39 struct radeon_cs_reloc {
40 struct radeon_bo *bo;
41 uint32_t read_domain;
42 uint32_t write_domain;
43 uint32_t flags;
44 };
45
46
47 #define RADEON_CS_SPACE_OK 0
48 #define RADEON_CS_SPACE_OP_TO_BIG 1
49 #define RADEON_CS_SPACE_FLUSH 2
50
51 struct radeon_cs_space_check {
52 struct radeon_bo *bo;
53 uint32_t read_domains;
54 uint32_t write_domain;
55 uint32_t new_accounted;
56 };
57
58 struct radeon_cs_manager;
59
60 struct radeon_cs {
61 struct radeon_cs_manager *csm;
62 void *relocs;
63 uint32_t *packets;
64 unsigned crelocs;
65 unsigned relocs_total_size;
66 unsigned cdw;
67 unsigned ndw;
68 int section;
69 unsigned section_ndw;
70 unsigned section_cdw;
71 const char *section_file;
72 const char *section_func;
73 int section_line;
74
75 };
76
77 /* cs functions */
78 struct radeon_cs_funcs {
79 struct radeon_cs *(*cs_create)(struct radeon_cs_manager *csm,
80 uint32_t ndw);
81 int (*cs_write_reloc)(struct radeon_cs *cs,
82 struct radeon_bo *bo,
83 uint32_t read_domain,
84 uint32_t write_domain,
85 uint32_t flags);
86 int (*cs_begin)(struct radeon_cs *cs,
87 uint32_t ndw,
88 const char *file,
89 const char *func,
90 int line);
91 int (*cs_end)(struct radeon_cs *cs,
92 const char *file,
93 const char *func,
94 int line);
95 int (*cs_emit)(struct radeon_cs *cs);
96 int (*cs_destroy)(struct radeon_cs *cs);
97 int (*cs_erase)(struct radeon_cs *cs);
98 int (*cs_need_flush)(struct radeon_cs *cs);
99 void (*cs_print)(struct radeon_cs *cs, FILE *file);
100 int (*cs_space_check)(struct radeon_cs *cs, struct radeon_cs_space_check *bos,
101 int num_bo);
102 };
103
104 struct radeon_cs_manager {
105 struct radeon_cs_funcs *funcs;
106 int fd;
107 uint32_t vram_limit, gart_limit;
108 uint32_t vram_write_used, gart_write_used;
109 uint32_t read_used;
110 };
111
112 static inline struct radeon_cs *radeon_cs_create(struct radeon_cs_manager *csm,
113 uint32_t ndw)
114 {
115 return csm->funcs->cs_create(csm, ndw);
116 }
117
118 static inline int radeon_cs_write_reloc(struct radeon_cs *cs,
119 struct radeon_bo *bo,
120 uint32_t read_domain,
121 uint32_t write_domain,
122 uint32_t flags)
123 {
124 return cs->csm->funcs->cs_write_reloc(cs,
125 bo,
126 read_domain,
127 write_domain,
128 flags);
129 }
130
131 static inline int radeon_cs_begin(struct radeon_cs *cs,
132 uint32_t ndw,
133 const char *file,
134 const char *func,
135 int line)
136 {
137 return cs->csm->funcs->cs_begin(cs, ndw, file, func, line);
138 }
139
140 static inline int radeon_cs_end(struct radeon_cs *cs,
141 const char *file,
142 const char *func,
143 int line)
144 {
145 return cs->csm->funcs->cs_end(cs, file, func, line);
146 }
147
148 static inline int radeon_cs_emit(struct radeon_cs *cs)
149 {
150 return cs->csm->funcs->cs_emit(cs);
151 }
152
153 static inline int radeon_cs_destroy(struct radeon_cs *cs)
154 {
155 return cs->csm->funcs->cs_destroy(cs);
156 }
157
158 static inline int radeon_cs_erase(struct radeon_cs *cs)
159 {
160 return cs->csm->funcs->cs_erase(cs);
161 }
162
163 static inline int radeon_cs_need_flush(struct radeon_cs *cs)
164 {
165 return cs->csm->funcs->cs_need_flush(cs);
166 }
167
168 static inline void radeon_cs_print(struct radeon_cs *cs, FILE *file)
169 {
170 cs->csm->funcs->cs_print(cs, file);
171 }
172
173 static inline int radeon_cs_space_check(struct radeon_cs *cs,
174 struct radeon_cs_space_check *bos,
175 int num_bo)
176 {
177 return cs->csm->funcs->cs_space_check(cs, bos, num_bo);
178 }
179
180 static inline void radeon_cs_set_limit(struct radeon_cs *cs, uint32_t domain, uint32_t limit)
181 {
182
183 if (domain == RADEON_GEM_DOMAIN_VRAM)
184 cs->csm->vram_limit = limit;
185 else
186 cs->csm->gart_limit = limit;
187 }
188
189 static inline void radeon_cs_write_dword(struct radeon_cs *cs, uint32_t dword)
190 {
191 cs->packets[cs->cdw++] = dword;
192 if (cs->section) {
193 cs->section_cdw++;
194 }
195 }
196
197 #endif