1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
|
/*
* Copyright © 2010 Jerome Glisse <glisse@freedesktop.org>
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of version 2 of the GNU General Public License
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef RADEON_DEVICE_H
#define RADEON_DEVICE_H
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "xf86drm.h"
#include "radeon_bo.h"
#include "radeon_drm.h"
#include "list.h"
/* UTILITIES ****************************************************************/
typedef uint8_t u8;
typedef uint32_t u32;
typedef uint64_t u64;
#define GFP_KERNEL 0
#define kmalloc(s, gfp) malloc(s)
#define kfree(p) free(p)
#define dev_err(d, p, args...) fprintf(stderr, p, ##args)
struct kref {
int refcount;
};
void kref_set(struct kref *kref, int num);
void kref_init(struct kref *kref);
void kref_get(struct kref *kref);
int kref_put(struct kref *kref, void (*release) (struct kref *kref));
/**
* container_of - cast a member of a structure out to the containing structure
* @ptr: the pointer to the member.
* @type: the type of the container struct this is embedded in.
* @member: the name of the member within the struct.
*
*/
#define container_of(ptr, type, member) ({ \
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
(type *)( (char *)__mptr - offsetof(type,member) );})
#define radeon_bo_size(bo) ((bo)->size)
/* UTILITIES END ************************************************************/
struct radeon_device;
struct radeon_atom;
struct radeon_ib {
u32 *ptr;
u32 cpkts;
u32 length_dw;
u32 *relocs;
u32 crelocs;
u32 nrelocs;
};
struct radeon_atom_flush {
struct list_head list;
u32 flags;
struct radeon_bo *bo;
};
typedef int (*radeon_atom_create_t)(struct radeon_device*, struct radeon_atom*, void*);
typedef int (*radeon_atom_emit_t)(struct radeon_device*, struct radeon_atom*, void*, struct radeon_ib*);
struct radeon_atom {
struct list_head list;
struct kref kref;
u32 type;
u32 id;
u32 nflushes;
u32 npkts;
u32 nbo;
u32 pkts[256];
struct radeon_bo *bo[32];
u32 flags[32];
void *state;
radeon_atom_emit_t emit;
};
struct r600_atom_funcs {
u32 type;
u32 size;
radeon_atom_create_t create;
radeon_atom_emit_t emit;
};
/* R600 */
struct drm_r600_vs_buffer {
u32 handle;
u32 resource_id;
u32 sq_vtx_constant_word0;
u32 sq_vtx_constant_word2;
u32 sq_vtx_constant_word3;
};
struct drm_r600_vs_element {
u32 buffer_id;
u32 semantic;
u32 sq_vtx_word0;
u32 sq_vtx_word1;
u32 sq_vtx_word2;
};
struct drm_r600_vs_input {
u32 nelements;
u32 nbuffers;
struct drm_r600_vs_element elements[32];
struct drm_r600_vs_buffer buffers[32];
};
struct r600_vs_input {
struct drm_r600_vs_input drm;
struct radeon_bo *bo[32];
u32 nbo;
};
struct r600_vs_buffer {
struct drm_r600_vs_buffer drm;
struct radeon_bo *bo;
};
struct drm_r600_batch {
struct radeon_atom *vs_constants;
struct radeon_atom *ps_constants;
struct radeon_atom *blend;
struct radeon_atom *cb;
struct radeon_atom *cb_cntl;
struct radeon_atom *pa;
struct radeon_atom *vport;
struct radeon_atom *db;
struct radeon_atom *db_cntl;
struct radeon_atom *vs_shader;
struct radeon_atom *ps_shader;
struct r600_vs_input inputs;
};
#define R600_BATCH_NATOMS 11
struct r600_batch {
struct list_head list;
struct list_head pre_flushes;
struct list_head post_flushes;
struct radeon_atom *atoms[R600_BATCH_NATOMS];
struct radeon_atom *emit_atoms[R600_BATCH_NATOMS];
u32 nemit_atoms;
u32 nflushes;
u32 npkts;
struct radeon_bo *shaders;
u32 shaders_idx;
struct r600_vs_input inputs;
u32 nfs_resources;
};
struct r600_batches {
struct radeon_ib *ib;
u32 npkts;
struct list_head batches;
u32 nfs_resources;
struct r600_vs_buffer fs_resource[160];
u32 last_id[R600_BATCH_NATOMS];
};
/* vs_shader - vertex shader */
struct drm_r600_vs_shader {
u32 sq_pgm_resources_vs;
u8 input_semantic[32];
u8 input_gpr[32];
u8 ninputs;
u8 output_semantic[32];
u8 fog_output_id;
u8 noutputs;
u32 ndwords;
u32 opcodes[512];
};
struct radeon_device {
int fd;
struct radeon_bo *bo[32];
u32 nbo;
struct r600_batches batches;
unsigned npipes;
unsigned nbanks;
unsigned group_bytes;
struct radeon_bo_manager *bom;
};
extern int r600_shader_build_fs(struct radeon_device *rdev,
u32 *bytecode, u32 *ndwords,
struct drm_r600_vs_input *inputs,
struct drm_r600_vs_shader *vs);
extern int r600_batches_queue(struct radeon_device *rdev,
struct drm_r600_batch *batch);
extern u32 radeon_ib_reloc(struct radeon_ib *ib, struct radeon_bo *bo, u32 d);
extern int radeon_ib_get(struct radeon_device *rdev, struct radeon_ib **ib);
extern void radeon_ib_free(struct radeon_ib *ib);
extern int radeon_ib_schedule(struct radeon_device *rdev, struct radeon_ib *ib);
extern void radeon_atom_flush_cleanup(struct list_head *flushes);
extern int radeon_atom_flush_add(struct list_head *flushes, struct radeon_bo *bo, u32 flags);
extern int radeon_atom_emit_default(struct radeon_device *rdev, struct radeon_atom *atom,
void *data, struct radeon_ib *ib);
extern void radeon_atom_release(struct kref *kref);
extern void radeon_device_set_bo_list(struct radeon_device *rdev, u32 nbo, struct radeon_bo **bo);
extern struct radeon_bo *radeon_bo_lookup(struct radeon_device *rdev, u32 handle);
extern u64 crc_64(void *d, size_t len);
/* R700 */
extern void r700_batches_states_default(struct radeon_device *rdev, struct r600_batches *batches);
static inline void radeon_atom_put(struct radeon_atom *atom)
{
kref_put(&atom->kref, radeon_atom_release);
}
static inline int radeon_ib_begin(struct radeon_ib *ib, u32 ndw)
{
if ((ib->cpkts + ndw) > ib->length_dw)
return -ENOMEM;
return 0;
}
static inline int radeon_ib_copy(struct radeon_ib *ib, u32 *pkts, u32 ndw)
{
if ((ib->cpkts + ndw) > ib->length_dw) {
fprintf(stderr, "IB FULL !\n");
return -ENOMEM;
}
memcpy(&ib->ptr[ib->cpkts], pkts, ndw * 4);
ib->cpkts += ndw;
return 0;
}
#endif
|