1#ifndef __NOUVEAU_H__
2#define __NOUVEAU_H__
3
4#include <stdint.h>
5#include <stdbool.h>
6
7/* Supported class information, provided by the kernel */
8struct nouveau_sclass {
9	int32_t oclass;
10	int minver;
11	int maxver;
12};
13
14/* Client-provided array describing class versions that are desired.
15 *
16 * These are used to match against the kernel's list of supported classes.
17 */
18struct nouveau_mclass {
19	int32_t oclass;
20	int version;
21	void *data;
22};
23
24struct nouveau_object {
25	struct nouveau_object *parent;
26	uint64_t handle;
27	uint32_t oclass;
28	uint32_t length;	/* deprecated */
29	void *data;		/* deprecated */
30};
31
32int nouveau_object_new(struct nouveau_object *parent, uint64_t handle,
33		       uint32_t oclass, void *data, uint32_t length,
34		       struct nouveau_object **);
35void nouveau_object_del(struct nouveau_object **);
36int nouveau_object_mthd(struct nouveau_object *, uint32_t mthd,
37			void *data, uint32_t size);
38int nouveau_object_sclass_get(struct nouveau_object *,
39			      struct nouveau_sclass **);
40void nouveau_object_sclass_put(struct nouveau_sclass **);
41int nouveau_object_mclass(struct nouveau_object *,
42			  const struct nouveau_mclass *);
43
44struct nouveau_drm {
45	struct nouveau_object client;
46	int fd;
47	uint32_t version;
48	bool nvif;
49};
50
51static inline struct nouveau_drm *
52nouveau_drm(struct nouveau_object *obj)
53{
54	while (obj && obj->parent)
55		obj = obj->parent;
56	return (struct nouveau_drm *)obj;
57}
58
59int nouveau_drm_new(int fd, struct nouveau_drm **);
60void nouveau_drm_del(struct nouveau_drm **);
61
62struct nouveau_device {
63	struct nouveau_object object;
64	int fd;			/* deprecated */
65	uint32_t lib_version;	/* deprecated */
66	uint32_t drm_version;	/* deprecated */
67	uint32_t chipset;
68	uint64_t vram_size;
69	uint64_t gart_size;
70	uint64_t vram_limit;
71	uint64_t gart_limit;
72};
73
74int nouveau_device_new(struct nouveau_object *parent, int32_t oclass,
75		       void *data, uint32_t size, struct nouveau_device **);
76void nouveau_device_del(struct nouveau_device **);
77
78int nouveau_getparam(struct nouveau_device *, uint64_t param, uint64_t *value);
79int nouveau_setparam(struct nouveau_device *, uint64_t param, uint64_t value);
80
81/* deprecated */
82int nouveau_device_wrap(int fd, int close, struct nouveau_device **);
83int nouveau_device_open(const char *busid, struct nouveau_device **);
84
85struct nouveau_client {
86	struct nouveau_device *device;
87	int id;
88};
89
90int nouveau_client_new(struct nouveau_device *, struct nouveau_client **);
91void nouveau_client_del(struct nouveau_client **);
92
93union nouveau_bo_config {
94	struct {
95#define NV04_BO_16BPP 0x00000001
96#define NV04_BO_32BPP 0x00000002
97#define NV04_BO_ZETA  0x00000004
98		uint32_t surf_flags;
99		uint32_t surf_pitch;
100	} nv04;
101	struct {
102		uint32_t memtype;
103		uint32_t tile_mode;
104	} nv50;
105	struct {
106		uint32_t memtype;
107		uint32_t tile_mode;
108	} nvc0;
109	uint32_t data[8];
110};
111
112#define NOUVEAU_BO_VRAM    0x00000001
113#define NOUVEAU_BO_GART    0x00000002
114#define NOUVEAU_BO_APER   (NOUVEAU_BO_VRAM | NOUVEAU_BO_GART)
115#define NOUVEAU_BO_RD      0x00000100
116#define NOUVEAU_BO_WR      0x00000200
117#define NOUVEAU_BO_RDWR   (NOUVEAU_BO_RD | NOUVEAU_BO_WR)
118#define NOUVEAU_BO_NOBLOCK 0x00000400
119#define NOUVEAU_BO_LOW     0x00001000
120#define NOUVEAU_BO_HIGH    0x00002000
121#define NOUVEAU_BO_OR      0x00004000
122#define NOUVEAU_BO_MAP     0x80000000
123#define NOUVEAU_BO_CONTIG  0x40000000
124#define NOUVEAU_BO_NOSNOOP 0x20000000
125#define NOUVEAU_BO_COHERENT 0x10000000
126
127struct nouveau_bo {
128	struct nouveau_device *device;
129	uint32_t handle;
130	uint64_t size;
131	uint32_t flags;
132	uint64_t offset;
133	void *map;
134	union nouveau_bo_config config;
135};
136
137int nouveau_bo_new(struct nouveau_device *, uint32_t flags, uint32_t align,
138		   uint64_t size, union nouveau_bo_config *,
139		   struct nouveau_bo **);
140int nouveau_bo_wrap(struct nouveau_device *, uint32_t handle,
141		    struct nouveau_bo **);
142int nouveau_bo_name_ref(struct nouveau_device *v, uint32_t name,
143			struct nouveau_bo **);
144int nouveau_bo_name_get(struct nouveau_bo *, uint32_t *name);
145void nouveau_bo_ref(struct nouveau_bo *, struct nouveau_bo **);
146int nouveau_bo_map(struct nouveau_bo *, uint32_t access,
147		   struct nouveau_client *);
148int nouveau_bo_wait(struct nouveau_bo *, uint32_t access,
149		    struct nouveau_client *);
150int nouveau_bo_prime_handle_ref(struct nouveau_device *, int prime_fd,
151				struct nouveau_bo **);
152int nouveau_bo_set_prime(struct nouveau_bo *, int *prime_fd);
153
154struct nouveau_list {
155	struct nouveau_list *prev;
156	struct nouveau_list *next;
157};
158
159struct nouveau_bufref {
160	struct nouveau_list thead;
161	struct nouveau_bo *bo;
162	uint32_t packet;
163	uint32_t flags;
164	uint32_t data;
165	uint32_t vor;
166	uint32_t tor;
167	uint32_t priv_data;
168	void *priv;
169};
170
171struct nouveau_bufctx {
172	struct nouveau_client *client;
173	struct nouveau_list head;
174	struct nouveau_list pending;
175	struct nouveau_list current;
176	int relocs;
177};
178
179int nouveau_bufctx_new(struct nouveau_client *, int bins,
180		       struct nouveau_bufctx **);
181void nouveau_bufctx_del(struct nouveau_bufctx **);
182struct nouveau_bufref *
183nouveau_bufctx_refn(struct nouveau_bufctx *, int bin,
184		    struct nouveau_bo *, uint32_t flags);
185struct nouveau_bufref *
186nouveau_bufctx_mthd(struct nouveau_bufctx *, int bin,  uint32_t packet,
187		    struct nouveau_bo *, uint64_t data, uint32_t flags,
188		    uint32_t vor, uint32_t tor);
189void nouveau_bufctx_reset(struct nouveau_bufctx *, int bin);
190
191struct nouveau_pushbuf_krec;
192struct nouveau_pushbuf {
193	struct nouveau_client *client;
194	struct nouveau_object *channel;
195	struct nouveau_bufctx *bufctx;
196	void (*kick_notify)(struct nouveau_pushbuf *);
197	void *user_priv;
198	uint32_t rsvd_kick;
199	uint32_t flags;
200	uint32_t *cur;
201	uint32_t *end;
202};
203
204struct nouveau_pushbuf_refn {
205	struct nouveau_bo *bo;
206	uint32_t flags;
207};
208
209int nouveau_pushbuf_new(struct nouveau_client *, struct nouveau_object *chan,
210			int nr, uint32_t size, bool immediate,
211			struct nouveau_pushbuf **);
212void nouveau_pushbuf_del(struct nouveau_pushbuf **);
213int nouveau_pushbuf_space(struct nouveau_pushbuf *, uint32_t dwords,
214			  uint32_t relocs, uint32_t pushes);
215void nouveau_pushbuf_data(struct nouveau_pushbuf *, struct nouveau_bo *,
216			  uint64_t offset, uint64_t length);
217int nouveau_pushbuf_refn(struct nouveau_pushbuf *,
218			 struct nouveau_pushbuf_refn *, int nr);
219/* Emits a reloc into the push buffer at the current position, you *must*
220 * have previously added the referenced buffer to a buffer context, and
221 * validated it against the current push buffer.
222 */
223void nouveau_pushbuf_reloc(struct nouveau_pushbuf *, struct nouveau_bo *,
224			   uint32_t data, uint32_t flags,
225			   uint32_t vor, uint32_t tor);
226int nouveau_pushbuf_validate(struct nouveau_pushbuf *);
227uint32_t nouveau_pushbuf_refd(struct nouveau_pushbuf *, struct nouveau_bo *);
228int nouveau_pushbuf_kick(struct nouveau_pushbuf *, struct nouveau_object *chan);
229struct nouveau_bufctx *
230nouveau_pushbuf_bufctx(struct nouveau_pushbuf *, struct nouveau_bufctx *);
231
232#define NOUVEAU_DEVICE_CLASS       0x80000000
233#define NOUVEAU_FIFO_CHANNEL_CLASS 0x80000001
234#define NOUVEAU_NOTIFIER_CLASS     0x80000002
235
236struct nouveau_fifo {
237	struct nouveau_object *object;
238	uint32_t channel;
239	uint32_t pushbuf;
240	uint64_t unused1[3];
241};
242
243struct nv04_fifo {
244	struct nouveau_fifo base;
245	uint32_t vram;
246	uint32_t gart;
247	uint32_t notify;
248};
249
250struct nvc0_fifo {
251	struct nouveau_fifo base;
252	uint32_t notify;
253};
254
255#define NVE0_FIFO_ENGINE_GR  0x00000001
256#define NVE0_FIFO_ENGINE_VP  0x00000002
257#define NVE0_FIFO_ENGINE_PPP 0x00000004
258#define NVE0_FIFO_ENGINE_BSP 0x00000008
259#define NVE0_FIFO_ENGINE_CE0 0x00000010
260#define NVE0_FIFO_ENGINE_CE1 0x00000020
261#define NVE0_FIFO_ENGINE_ENC 0x00000040
262
263struct nve0_fifo {
264	struct {
265		struct nouveau_fifo base;
266		uint32_t notify;
267	};
268	uint32_t engine;
269};
270
271struct nv04_notify {
272	struct nouveau_object *object;
273	uint32_t offset;
274	uint32_t length;
275};
276#endif
277