c284f6aa7d17389f3dd0b2bf9deb28e68289af36
[mesa.git] / src / gallium / winsys / r600 / drm / radeon_priv.h
1 /*
2 * Copyright © 2009 Jerome Glisse <glisse@freedesktop.org>
3 *
4 * This file is free software; you can redistribute it and/or modify
5 * it under the terms of version 2 of the GNU General Public License
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software Foundation,
15 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
16 */
17 #ifndef RADEON_PRIV_H
18 #define RADEON_PRIV_H
19
20 #include <stdint.h>
21 #include "xf86drm.h"
22 #include "xf86drmMode.h"
23 #include <errno.h>
24 #include "radeon.h"
25
26 #include "pipe/p_compiler.h"
27 #include "util/u_inlines.h"
28 #include "pipe/p_defines.h"
29
30 struct radeon;
31 struct radeon_ctx;
32
33
34 /*
35 * radeon functions
36 */
37 typedef int (*radeon_state_pm4_t)(struct radeon_state *state);
38 struct radeon_register {
39 unsigned offset;
40 unsigned need_reloc;
41 unsigned bo_id;
42 char name[64];
43 };
44
45 struct radeon_bo {
46 struct pipe_reference reference;
47 unsigned handle;
48 unsigned size;
49 unsigned alignment;
50 unsigned map_count;
51 void *data;
52 };
53
54 struct radeon_sub_type {
55 int shader_type;
56 const struct radeon_register *regs;
57 unsigned nstates;
58 };
59
60 struct radeon_stype_info {
61 unsigned stype;
62 unsigned num;
63 unsigned stride;
64 radeon_state_pm4_t pm4;
65 struct radeon_sub_type reginfo[R600_SHADER_MAX];
66 unsigned base_id;
67 unsigned npm4;
68 };
69
70 struct radeon_ctx {
71 struct radeon *radeon;
72 u32 *pm4;
73 int cdwords;
74 int ndwords;
75 unsigned nreloc;
76 struct radeon_cs_reloc *reloc;
77 unsigned nbo;
78 struct radeon_bo **bo;
79 };
80
81 struct radeon {
82 int fd;
83 int refcount;
84 unsigned device;
85 unsigned family;
86 unsigned nstype;
87 struct radeon_stype_info *stype;
88 unsigned max_states;
89 boolean use_mem_constant; /* true for evergreen */
90 struct pb_manager *mman; /* malloc manager */
91 struct pb_manager *kman; /* kernel bo manager */
92 struct pb_manager *cman; /* cached bo manager */
93 };
94
95 struct radeon_ws_bo {
96 struct pipe_reference reference;
97 struct pb_buffer *pb;
98 };
99
100 extern struct radeon *radeon_new(int fd, unsigned device);
101 extern struct radeon *radeon_incref(struct radeon *radeon);
102 extern struct radeon *radeon_decref(struct radeon *radeon);
103 extern unsigned radeon_family_from_device(unsigned device);
104 extern int radeon_is_family_compatible(unsigned family1, unsigned family2);
105
106 /*
107 * r600/r700 context functions
108 */
109 extern int r600_init(struct radeon *radeon);
110 extern int r600_ctx_draw(struct radeon_ctx *ctx);
111 extern int r600_ctx_next_reloc(struct radeon_ctx *ctx, unsigned *reloc);
112
113 /*
114 * radeon state functions
115 */
116 extern u32 radeon_state_register_get(struct radeon_state *state, unsigned offset);
117 extern int radeon_state_register_set(struct radeon_state *state, unsigned offset, u32 value);
118 extern struct radeon_state *radeon_state_duplicate(struct radeon_state *state);
119 extern int radeon_state_replace_always(struct radeon_state *ostate, struct radeon_state *nstate);
120 extern int radeon_state_pm4_generic(struct radeon_state *state);
121 extern int radeon_state_reloc(struct radeon_state *state, unsigned id, unsigned bo_id);
122
123 /*
124 * radeon draw functions
125 */
126 extern int radeon_draw_pm4(struct radeon_draw *draw);
127
128 /* ws bo winsys only */
129 unsigned radeon_ws_bo_get_handle(struct radeon_ws_bo *bo);
130 unsigned radeon_ws_bo_get_size(struct radeon_ws_bo *bo);
131
132 /* bo */
133 struct radeon_bo *radeon_bo(struct radeon *radeon, unsigned handle,
134 unsigned size, unsigned alignment, void *ptr);
135 int radeon_bo_map(struct radeon *radeon, struct radeon_bo *bo);
136 void radeon_bo_unmap(struct radeon *radeon, struct radeon_bo *bo);
137 void radeon_bo_reference(struct radeon *radeon, struct radeon_bo **dst,
138 struct radeon_bo *src);
139 int radeon_bo_wait(struct radeon *radeon, struct radeon_bo *bo);
140 int radeon_bo_busy(struct radeon *radeon, struct radeon_bo *bo, uint32_t *domain);
141
142 /* pipebuffer kernel bo manager */
143 struct pb_manager *radeon_bo_pbmgr_create(struct radeon *radeon);
144 struct radeon_bo *radeon_bo_pb_get_bo(struct pb_buffer *_buf);
145 void radeon_bo_pbmgr_flush_maps(struct pb_manager *_mgr);
146 struct pb_buffer *radeon_bo_pb_create_buffer_from_handle(struct pb_manager *_mgr,
147 uint32_t handle);
148
149 #endif