summaryrefslogtreecommitdiff
path: root/r600.h
blob: 7805f0561e7b70c2a8697dd97c9aa9280777c422 (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
/*
 * Copyright 2010 Jerome Glisse <glisse@freedesktop.org>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * on the rights to use, copy, modify, merge, publish, distribute, sub
 * license, and/or sell copies of the Software, and to permit persons to whom
 * the Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
 * USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 * Authors:
 *      Jerome Glisse
 */
#ifndef R600_H
#define R600_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 "r600_winsys.h"

#define R600_MAX_WORK	256

struct r600_winsys;
struct r600_atom;

struct radeon_ib {
	u32	*ptr;
	u32	cpkts;
	u32	length_dw;
	u32	*relocs;
	u32	crelocs;
	u32	nrelocs;
};

typedef int (*r600_atom_create_t)(struct r600_winsys*, struct r600_atom*, void*);
typedef int (*r600_atom_emit_t)(struct r600_winsys*, struct r600_atom*, void*, struct radeon_ib*);

struct r600_atom {
	int				refcount;
	u32				type;
	u32				id;
	u32				nflushes;
	u32				npkts;
	u32				nbo;
	u32				pkts[1024];
	struct radeon_bo		*bo[32];
	u32				flags[32];
	void				*state;
	r600_atom_emit_t		emit;
};

struct r600_atom_flush {
	u32			flags;
	struct radeon_bo	*bo;
};

struct r600_work {
	struct r600_atom		*atoms[R600_BATCH_NATOMS];
	struct r600_atom		*emit_atoms[R600_BATCH_NATOMS];
	u32				nemit_atoms;
	u32				nflush;
	struct r600_atom_flush		flush[480];
	u32				npkts;
	struct r600_batch		drm;
};

struct r600_scheduler {
	struct radeon_ib		*ib;
	u32				npkts;
	u32				nwork;
	struct r600_work		work[R600_MAX_WORK];
	u32				last_id[R600_BATCH_NATOMS];
};

struct r600_winsys {
	int				fd;
	struct radeon_bo		*bo[32];
	u32				nbo;
	struct r600_scheduler		scheduler;
	unsigned			npipes;
	unsigned			nbanks;
	unsigned			group_bytes;
	struct radeon_bo_manager	*bom;
};

extern void r600_atom_ref(struct r600_atom *atom);
extern u32 radeon_ib_reloc(struct radeon_ib *ib, struct radeon_bo *bo, u32 d);
extern int radeon_ib_get(struct r600_winsys *rdev, struct radeon_ib **ib);
extern void radeon_ib_free(struct radeon_ib *ib);
extern int radeon_ib_schedule(struct r600_winsys *rdev, struct radeon_ib *ib);
extern int r600_atom_emit_default(struct r600_winsys *rdev, struct r600_atom *atom,
					void *data, struct radeon_ib *ib);
extern void r600_winsys_set_bo_list(struct r600_winsys *rdev, u32 nbo, struct radeon_bo **bo);
extern struct radeon_bo *radeon_bo_lookup(struct r600_winsys *rdev, u32 handle);
extern u64 crc_64(void *d, size_t len);
/* R700 */
extern void r700_scheduler_states_default(struct r600_winsys *rdev, struct r600_scheduler *scheduler);
extern int r600_atoms_init(struct r600_winsys *rdev);
extern int r600_draw_cmd_size(struct r600_batch *batch);
extern int r600_draw_cmd_emit(struct radeon_ib *ib, struct r600_batch *batch);
extern void r600_memcpy_bo(struct radeon_bo *bo, u32 *src, u32 size);

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