8f0b449e41f10ffed8dce03ffdadbf2d5ac15314
2 * Copyright © 2008 Nicolai Haehnle
3 * Copyright © 2008 Jérôme Glisse
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:
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.
22 * The above copyright notice and this permission notice (including the
23 * next paragraph) shall be included in all copies or substantial portions
28 * Aapo Tahkola <aet@rasterburn.org>
29 * Nicolai Haehnle <prefect_@gmx.net>
30 * Jérôme Glisse <glisse@freedesktop.org>
37 #include "radeon_drm.h"
39 struct radeon_cs_reloc
{
42 uint32_t write_domain
;
47 #define RADEON_CS_SPACE_OK 0
48 #define RADEON_CS_SPACE_OP_TO_BIG 1
49 #define RADEON_CS_SPACE_FLUSH 2
51 struct radeon_cs_space_check
{
53 uint32_t read_domains
;
54 uint32_t write_domain
;
55 uint32_t new_accounted
;
58 struct radeon_cs_manager
;
61 struct radeon_cs_manager
*csm
;
65 unsigned relocs_total_size
;
71 const char *section_file
;
72 const char *section_func
;
78 struct radeon_cs_funcs
{
79 struct radeon_cs
*(*cs_create
)(struct radeon_cs_manager
*csm
,
81 int (*cs_write_reloc
)(struct radeon_cs
*cs
,
84 uint32_t write_domain
,
86 int (*cs_begin
)(struct radeon_cs
*cs
,
91 int (*cs_end
)(struct radeon_cs
*cs
,
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
,
104 struct radeon_cs_manager
{
105 struct radeon_cs_funcs
*funcs
;
107 uint32_t vram_limit
, gart_limit
;
108 uint32_t vram_write_used
, gart_write_used
;
112 static inline struct radeon_cs
*radeon_cs_create(struct radeon_cs_manager
*csm
,
115 return csm
->funcs
->cs_create(csm
, ndw
);
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
,
124 return cs
->csm
->funcs
->cs_write_reloc(cs
,
131 static inline int radeon_cs_begin(struct radeon_cs
*cs
,
137 return cs
->csm
->funcs
->cs_begin(cs
, ndw
, file
, func
, line
);
140 static inline int radeon_cs_end(struct radeon_cs
*cs
,
145 return cs
->csm
->funcs
->cs_end(cs
, file
, func
, line
);
148 static inline int radeon_cs_emit(struct radeon_cs
*cs
)
150 return cs
->csm
->funcs
->cs_emit(cs
);
153 static inline int radeon_cs_destroy(struct radeon_cs
*cs
)
155 return cs
->csm
->funcs
->cs_destroy(cs
);
158 static inline int radeon_cs_erase(struct radeon_cs
*cs
)
160 return cs
->csm
->funcs
->cs_erase(cs
);
163 static inline int radeon_cs_need_flush(struct radeon_cs
*cs
)
165 return cs
->csm
->funcs
->cs_need_flush(cs
);
168 static inline void radeon_cs_print(struct radeon_cs
*cs
, FILE *file
)
170 cs
->csm
->funcs
->cs_print(cs
, file
);
173 static inline int radeon_cs_space_check(struct radeon_cs
*cs
,
174 struct radeon_cs_space_check
*bos
,
177 return cs
->csm
->funcs
->cs_space_check(cs
, bos
, num_bo
);
180 static inline void radeon_cs_set_limit(struct radeon_cs
*cs
, uint32_t domain
, uint32_t limit
)
183 if (domain
== RADEON_GEM_DOMAIN_VRAM
)
184 cs
->csm
->vram_limit
= limit
;
186 cs
->csm
->gart_limit
= limit
;
189 static inline void radeon_cs_write_dword(struct radeon_cs
*cs
, uint32_t dword
)
191 cs
->packets
[cs
->cdw
++] = dword
;