summaryrefslogtreecommitdiff
path: root/radeon_device.h
blob: e8704f831d78c0496c00511b41190172a34da0af (plain)
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
/*
 * 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 ************************************************************/

#include "r600_atom_kernel.h"

struct radeon_device;
struct radeon_atom;
struct drm_r600_vs_input;
struct drm_r600_vs_shader;

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;
};

struct r600_vs_buffer {
	struct drm_r600_vs_buffer	drm;
	struct radeon_bo		*bo;
};

struct r600_vs_input {
	struct drm_r600_vs_input	drm;
	struct radeon_bo		*bo[32];
	u32				nbo;
};

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;
	u32				nfs_resources;
	struct r600_vs_input		inputs;
};

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];
};

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 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