1e88f27b3Smrg#ifndef __NOUVEAU_H__
2e88f27b3Smrg#define __NOUVEAU_H__
3e88f27b3Smrg
4e88f27b3Smrg#include <stdint.h>
5e88f27b3Smrg#include <stdbool.h>
6e88f27b3Smrg
73f012e29Smrg/* Supported class information, provided by the kernel */
83f012e29Smrgstruct nouveau_sclass {
93f012e29Smrg	int32_t oclass;
103f012e29Smrg	int minver;
113f012e29Smrg	int maxver;
123f012e29Smrg};
13e88f27b3Smrg
143f012e29Smrg/* Client-provided array describing class versions that are desired.
153f012e29Smrg *
163f012e29Smrg * These are used to match against the kernel's list of supported classes.
173f012e29Smrg */
183f012e29Smrgstruct nouveau_mclass {
193f012e29Smrg	int32_t oclass;
203f012e29Smrg	int version;
213f012e29Smrg	void *data;
22e88f27b3Smrg};
23e88f27b3Smrg
24e88f27b3Smrgstruct nouveau_object {
25e88f27b3Smrg	struct nouveau_object *parent;
26e88f27b3Smrg	uint64_t handle;
27e88f27b3Smrg	uint32_t oclass;
283f012e29Smrg	uint32_t length;	/* deprecated */
293f012e29Smrg	void *data;		/* deprecated */
30e88f27b3Smrg};
31e88f27b3Smrg
323f012e29Smrgint nouveau_object_new(struct nouveau_object *parent, uint64_t handle,
333f012e29Smrg		       uint32_t oclass, void *data, uint32_t length,
343f012e29Smrg		       struct nouveau_object **);
353f012e29Smrgvoid nouveau_object_del(struct nouveau_object **);
363f012e29Smrgint nouveau_object_mthd(struct nouveau_object *, uint32_t mthd,
373f012e29Smrg			void *data, uint32_t size);
383f012e29Smrgint nouveau_object_sclass_get(struct nouveau_object *,
393f012e29Smrg			      struct nouveau_sclass **);
403f012e29Smrgvoid nouveau_object_sclass_put(struct nouveau_sclass **);
413f012e29Smrgint nouveau_object_mclass(struct nouveau_object *,
423f012e29Smrg			  const struct nouveau_mclass *);
43e88f27b3Smrg
443f012e29Smrgstruct nouveau_drm {
453f012e29Smrg	struct nouveau_object client;
463f012e29Smrg	int fd;
473f012e29Smrg	uint32_t version;
483f012e29Smrg	bool nvif;
49e88f27b3Smrg};
50e88f27b3Smrg
513f012e29Smrgstatic inline struct nouveau_drm *
523f012e29Smrgnouveau_drm(struct nouveau_object *obj)
533f012e29Smrg{
543f012e29Smrg	while (obj && obj->parent)
553f012e29Smrg		obj = obj->parent;
563f012e29Smrg	return (struct nouveau_drm *)obj;
573f012e29Smrg}
58e88f27b3Smrg
593f012e29Smrgint nouveau_drm_new(int fd, struct nouveau_drm **);
603f012e29Smrgvoid nouveau_drm_del(struct nouveau_drm **);
61e88f27b3Smrg
62e88f27b3Smrgstruct nouveau_device {
63e88f27b3Smrg	struct nouveau_object object;
643f012e29Smrg	int fd;			/* deprecated */
653f012e29Smrg	uint32_t lib_version;	/* deprecated */
663f012e29Smrg	uint32_t drm_version;	/* deprecated */
67e88f27b3Smrg	uint32_t chipset;
68e88f27b3Smrg	uint64_t vram_size;
69e88f27b3Smrg	uint64_t gart_size;
70e88f27b3Smrg	uint64_t vram_limit;
71e88f27b3Smrg	uint64_t gart_limit;
72e88f27b3Smrg};
73e88f27b3Smrg
743f012e29Smrgint nouveau_device_new(struct nouveau_object *parent, int32_t oclass,
753f012e29Smrg		       void *data, uint32_t size, struct nouveau_device **);
76e88f27b3Smrgvoid nouveau_device_del(struct nouveau_device **);
773f012e29Smrg
783f012e29Smrgint nouveau_getparam(struct nouveau_device *, uint64_t param, uint64_t *value);
793f012e29Smrgint nouveau_setparam(struct nouveau_device *, uint64_t param, uint64_t value);
803f012e29Smrg
813f012e29Smrg/* deprecated */
823f012e29Smrgint nouveau_device_wrap(int fd, int close, struct nouveau_device **);
833f012e29Smrgint nouveau_device_open(const char *busid, struct nouveau_device **);
84e88f27b3Smrg
85e88f27b3Smrgstruct nouveau_client {
86e88f27b3Smrg	struct nouveau_device *device;
87e88f27b3Smrg	int id;
88e88f27b3Smrg};
89e88f27b3Smrg
903f012e29Smrgint nouveau_client_new(struct nouveau_device *, struct nouveau_client **);
91e88f27b3Smrgvoid nouveau_client_del(struct nouveau_client **);
92e88f27b3Smrg
93e88f27b3Smrgunion nouveau_bo_config {
94e88f27b3Smrg	struct {
95e88f27b3Smrg#define NV04_BO_16BPP 0x00000001
96e88f27b3Smrg#define NV04_BO_32BPP 0x00000002
97e88f27b3Smrg#define NV04_BO_ZETA  0x00000004
98e88f27b3Smrg		uint32_t surf_flags;
99e88f27b3Smrg		uint32_t surf_pitch;
100e88f27b3Smrg	} nv04;
101e88f27b3Smrg	struct {
102e88f27b3Smrg		uint32_t memtype;
103e88f27b3Smrg		uint32_t tile_mode;
104e88f27b3Smrg	} nv50;
105e88f27b3Smrg	struct {
106e88f27b3Smrg		uint32_t memtype;
107e88f27b3Smrg		uint32_t tile_mode;
108e88f27b3Smrg	} nvc0;
109e88f27b3Smrg	uint32_t data[8];
110e88f27b3Smrg};
111e88f27b3Smrg
112e88f27b3Smrg#define NOUVEAU_BO_VRAM    0x00000001
113e88f27b3Smrg#define NOUVEAU_BO_GART    0x00000002
114e88f27b3Smrg#define NOUVEAU_BO_APER   (NOUVEAU_BO_VRAM | NOUVEAU_BO_GART)
115e88f27b3Smrg#define NOUVEAU_BO_RD      0x00000100
116e88f27b3Smrg#define NOUVEAU_BO_WR      0x00000200
117e88f27b3Smrg#define NOUVEAU_BO_RDWR   (NOUVEAU_BO_RD | NOUVEAU_BO_WR)
118e88f27b3Smrg#define NOUVEAU_BO_NOBLOCK 0x00000400
119e88f27b3Smrg#define NOUVEAU_BO_LOW     0x00001000
120e88f27b3Smrg#define NOUVEAU_BO_HIGH    0x00002000
121e88f27b3Smrg#define NOUVEAU_BO_OR      0x00004000
122e88f27b3Smrg#define NOUVEAU_BO_MAP     0x80000000
123e88f27b3Smrg#define NOUVEAU_BO_CONTIG  0x40000000
124e88f27b3Smrg#define NOUVEAU_BO_NOSNOOP 0x20000000
125e6188e58Smrg#define NOUVEAU_BO_COHERENT 0x10000000
126e88f27b3Smrg
127e88f27b3Smrgstruct nouveau_bo {
128e88f27b3Smrg	struct nouveau_device *device;
129e88f27b3Smrg	uint32_t handle;
130e88f27b3Smrg	uint64_t size;
131e88f27b3Smrg	uint32_t flags;
132e88f27b3Smrg	uint64_t offset;
133e88f27b3Smrg	void *map;
134e88f27b3Smrg	union nouveau_bo_config config;
135e88f27b3Smrg};
136e88f27b3Smrg
1373f012e29Smrgint nouveau_bo_new(struct nouveau_device *, uint32_t flags, uint32_t align,
1383f012e29Smrg		   uint64_t size, union nouveau_bo_config *,
1393f012e29Smrg		   struct nouveau_bo **);
140bbff01ceSmrgvoid nouveau_bo_make_global(struct nouveau_bo *);
1413f012e29Smrgint nouveau_bo_wrap(struct nouveau_device *, uint32_t handle,
142e88f27b3Smrg		    struct nouveau_bo **);
1433f012e29Smrgint nouveau_bo_name_ref(struct nouveau_device *v, uint32_t name,
1443f012e29Smrg			struct nouveau_bo **);
1453f012e29Smrgint nouveau_bo_name_get(struct nouveau_bo *, uint32_t *name);
146e88f27b3Smrgvoid nouveau_bo_ref(struct nouveau_bo *, struct nouveau_bo **);
1473f012e29Smrgint nouveau_bo_map(struct nouveau_bo *, uint32_t access,
1483f012e29Smrg		   struct nouveau_client *);
1493f012e29Smrgint nouveau_bo_wait(struct nouveau_bo *, uint32_t access,
150e88f27b3Smrg		    struct nouveau_client *);
1513f012e29Smrgint nouveau_bo_prime_handle_ref(struct nouveau_device *, int prime_fd,
1523f012e29Smrg				struct nouveau_bo **);
1533f012e29Smrgint nouveau_bo_set_prime(struct nouveau_bo *, int *prime_fd);
1543f012e29Smrg
1553f012e29Smrgstruct nouveau_list {
1563f012e29Smrg	struct nouveau_list *prev;
1573f012e29Smrg	struct nouveau_list *next;
1583f012e29Smrg};
159e88f27b3Smrg
160e88f27b3Smrgstruct nouveau_bufref {
161e88f27b3Smrg	struct nouveau_list thead;
162e88f27b3Smrg	struct nouveau_bo *bo;
163e88f27b3Smrg	uint32_t packet;
164e88f27b3Smrg	uint32_t flags;
165e88f27b3Smrg	uint32_t data;
166e88f27b3Smrg	uint32_t vor;
167e88f27b3Smrg	uint32_t tor;
168e88f27b3Smrg	uint32_t priv_data;
169e88f27b3Smrg	void *priv;
170e88f27b3Smrg};
171e88f27b3Smrg
172e88f27b3Smrgstruct nouveau_bufctx {
173e88f27b3Smrg	struct nouveau_client *client;
174e88f27b3Smrg	struct nouveau_list head;
175e88f27b3Smrg	struct nouveau_list pending;
176e88f27b3Smrg	struct nouveau_list current;
177e88f27b3Smrg	int relocs;
178e88f27b3Smrg};
179e88f27b3Smrg
1803f012e29Smrgint nouveau_bufctx_new(struct nouveau_client *, int bins,
1813f012e29Smrg		       struct nouveau_bufctx **);
182e88f27b3Smrgvoid nouveau_bufctx_del(struct nouveau_bufctx **);
183e88f27b3Smrgstruct nouveau_bufref *
184e88f27b3Smrgnouveau_bufctx_refn(struct nouveau_bufctx *, int bin,
185e88f27b3Smrg		    struct nouveau_bo *, uint32_t flags);
186e88f27b3Smrgstruct nouveau_bufref *
187e88f27b3Smrgnouveau_bufctx_mthd(struct nouveau_bufctx *, int bin,  uint32_t packet,
188e88f27b3Smrg		    struct nouveau_bo *, uint64_t data, uint32_t flags,
189e88f27b3Smrg		    uint32_t vor, uint32_t tor);
190e88f27b3Smrgvoid nouveau_bufctx_reset(struct nouveau_bufctx *, int bin);
191e88f27b3Smrg
192e88f27b3Smrgstruct nouveau_pushbuf_krec;
193e88f27b3Smrgstruct nouveau_pushbuf {
194e88f27b3Smrg	struct nouveau_client *client;
195e88f27b3Smrg	struct nouveau_object *channel;
196e88f27b3Smrg	struct nouveau_bufctx *bufctx;
197e88f27b3Smrg	void (*kick_notify)(struct nouveau_pushbuf *);
198e88f27b3Smrg	void *user_priv;
199e88f27b3Smrg	uint32_t rsvd_kick;
200e88f27b3Smrg	uint32_t flags;
201e88f27b3Smrg	uint32_t *cur;
202e88f27b3Smrg	uint32_t *end;
203e88f27b3Smrg};
204e88f27b3Smrg
205e88f27b3Smrgstruct nouveau_pushbuf_refn {
206e88f27b3Smrg	struct nouveau_bo *bo;
207e88f27b3Smrg	uint32_t flags;
208e88f27b3Smrg};
209e88f27b3Smrg
2103f012e29Smrgint nouveau_pushbuf_new(struct nouveau_client *, struct nouveau_object *chan,
2113f012e29Smrg			int nr, uint32_t size, bool immediate,
2123f012e29Smrg			struct nouveau_pushbuf **);
213e88f27b3Smrgvoid nouveau_pushbuf_del(struct nouveau_pushbuf **);
2143f012e29Smrgint nouveau_pushbuf_space(struct nouveau_pushbuf *, uint32_t dwords,
2153f012e29Smrg			  uint32_t relocs, uint32_t pushes);
216e88f27b3Smrgvoid nouveau_pushbuf_data(struct nouveau_pushbuf *, struct nouveau_bo *,
217e88f27b3Smrg			  uint64_t offset, uint64_t length);
2183f012e29Smrgint nouveau_pushbuf_refn(struct nouveau_pushbuf *,
2193f012e29Smrg			 struct nouveau_pushbuf_refn *, int nr);
220e88f27b3Smrg/* Emits a reloc into the push buffer at the current position, you *must*
221e88f27b3Smrg * have previously added the referenced buffer to a buffer context, and
222e88f27b3Smrg * validated it against the current push buffer.
223e88f27b3Smrg */
224e88f27b3Smrgvoid nouveau_pushbuf_reloc(struct nouveau_pushbuf *, struct nouveau_bo *,
225e88f27b3Smrg			   uint32_t data, uint32_t flags,
226e88f27b3Smrg			   uint32_t vor, uint32_t tor);
2273f012e29Smrgint nouveau_pushbuf_validate(struct nouveau_pushbuf *);
228e88f27b3Smrguint32_t nouveau_pushbuf_refd(struct nouveau_pushbuf *, struct nouveau_bo *);
2293f012e29Smrgint nouveau_pushbuf_kick(struct nouveau_pushbuf *, struct nouveau_object *chan);
230e88f27b3Smrgstruct nouveau_bufctx *
231e88f27b3Smrgnouveau_pushbuf_bufctx(struct nouveau_pushbuf *, struct nouveau_bufctx *);
232e88f27b3Smrg
2333f012e29Smrg#define NOUVEAU_DEVICE_CLASS       0x80000000
2343f012e29Smrg#define NOUVEAU_FIFO_CHANNEL_CLASS 0x80000001
2353f012e29Smrg#define NOUVEAU_NOTIFIER_CLASS     0x80000002
2363f012e29Smrg
2373f012e29Smrgstruct nouveau_fifo {
2383f012e29Smrg	struct nouveau_object *object;
2393f012e29Smrg	uint32_t channel;
2403f012e29Smrg	uint32_t pushbuf;
2413f012e29Smrg	uint64_t unused1[3];
2423f012e29Smrg};
2433f012e29Smrg
2443f012e29Smrgstruct nv04_fifo {
2453f012e29Smrg	struct nouveau_fifo base;
2463f012e29Smrg	uint32_t vram;
2473f012e29Smrg	uint32_t gart;
2483f012e29Smrg	uint32_t notify;
2493f012e29Smrg};
2503f012e29Smrg
2513f012e29Smrgstruct nvc0_fifo {
2523f012e29Smrg	struct nouveau_fifo base;
2533f012e29Smrg	uint32_t notify;
2543f012e29Smrg};
2553f012e29Smrg
2563f012e29Smrg#define NVE0_FIFO_ENGINE_GR  0x00000001
2573f012e29Smrg#define NVE0_FIFO_ENGINE_VP  0x00000002
2583f012e29Smrg#define NVE0_FIFO_ENGINE_PPP 0x00000004
2593f012e29Smrg#define NVE0_FIFO_ENGINE_BSP 0x00000008
2603f012e29Smrg#define NVE0_FIFO_ENGINE_CE0 0x00000010
2613f012e29Smrg#define NVE0_FIFO_ENGINE_CE1 0x00000020
2623f012e29Smrg#define NVE0_FIFO_ENGINE_ENC 0x00000040
2633f012e29Smrg
2643f012e29Smrgstruct nve0_fifo {
2653f012e29Smrg	struct {
2663f012e29Smrg		struct nouveau_fifo base;
2673f012e29Smrg		uint32_t notify;
2683f012e29Smrg	};
2693f012e29Smrg	uint32_t engine;
2703f012e29Smrg};
2713f012e29Smrg
2723f012e29Smrgstruct nv04_notify {
2733f012e29Smrg	struct nouveau_object *object;
2743f012e29Smrg	uint32_t offset;
2753f012e29Smrg	uint32_t length;
2763f012e29Smrg};
2770ed5401bSmrg
2780ed5401bSmrgbool
2790ed5401bSmrgnouveau_check_dead_channel(struct nouveau_drm *, struct nouveau_object *chan);
2800ed5401bSmrg
281e88f27b3Smrg#endif
282