r300g: require DRM 2.3.0 (kernel 2.6.34)
[mesa.git] / src / gallium / drivers / r300 / r300_cs.h
1 /*
2 * Copyright 2008 Corbin Simpson <MostAwesomeDude@gmail.com>
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE. */
22
23 /**
24 * This file contains macros for immediate command submission.
25 */
26
27 #ifndef R300_CS_H
28 #define R300_CS_H
29
30 #include "r300_reg.h"
31 #include "r300_context.h"
32 #include "r300_winsys.h"
33
34 /* Yes, I know macros are ugly. However, they are much prettier than the code
35 * that they neatly hide away, and don't have the cost of function setup,so
36 * we're going to use them. */
37
38 /**
39 * Command submission setup.
40 */
41
42 #define CS_LOCALS(context) \
43 struct r300_winsys_cs *cs_copy = (context)->cs; \
44 struct r300_winsys_screen *cs_winsys = (context)->rws; \
45 int cs_count = 0; (void) cs_count; (void) cs_winsys;
46
47 #ifdef DEBUG
48
49 #define BEGIN_CS(size) do { \
50 assert(size <= (R300_MAX_CMDBUF_DWORDS - cs_copy->cdw)); \
51 cs_count = size; \
52 } while (0)
53
54 #define END_CS do { \
55 if (cs_count != 0) \
56 debug_printf("r300: Warning: cs_count off by %d at (%s, %s:%i)\n", \
57 cs_count, __FUNCTION__, __FILE__, __LINE__); \
58 cs_count = 0; \
59 } while (0)
60
61 #define CS_USED_DW(x) cs_count -= (x)
62
63 #else
64
65 #define BEGIN_CS(size)
66 #define END_CS
67 #define CS_USED_DW(x)
68
69 #endif
70
71 /**
72 * Writing pure DWORDs.
73 */
74
75 #define OUT_CS(value) do { \
76 cs_copy->buf[cs_copy->cdw++] = (value); \
77 CS_USED_DW(1); \
78 } while (0)
79
80 #define OUT_CS_32F(value) \
81 OUT_CS(fui(value))
82
83 #define OUT_CS_REG(register, value) do { \
84 OUT_CS(CP_PACKET0(register, 0)); \
85 OUT_CS(value); \
86 } while (0)
87
88 /* Note: This expects count to be the number of registers,
89 * not the actual packet0 count! */
90 #define OUT_CS_REG_SEQ(register, count) \
91 OUT_CS(CP_PACKET0((register), ((count) - 1)))
92
93 #define OUT_CS_ONE_REG(register, count) \
94 OUT_CS(CP_PACKET0((register), ((count) - 1)) | RADEON_ONE_REG_WR)
95
96 #define OUT_CS_PKT3(op, count) \
97 OUT_CS(CP_PACKET3(op, count))
98
99 #define OUT_CS_TABLE(values, count) do { \
100 memcpy(cs_copy->buf + cs_copy->cdw, values, count * 4); \
101 cs_copy->cdw += count; \
102 CS_USED_DW(count); \
103 } while (0)
104
105
106 /**
107 * Writing relocations.
108 */
109
110 #define OUT_CS_RELOC(r) do { \
111 assert((r)); \
112 assert((r)->cs_buf); \
113 cs_winsys->cs_write_reloc(cs_copy, (r)->cs_buf); \
114 CS_USED_DW(2); \
115 } while (0)
116
117
118 /**
119 * Command buffer emission.
120 */
121
122 #define WRITE_CS_TABLE(values, count) do { \
123 assert(cs_count == 0); \
124 memcpy(cs_copy->buf + cs_copy->cdw, (values), (count) * 4); \
125 cs_copy->cdw += (count); \
126 } while (0)
127
128 #endif /* R300_CS_H */