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 **); 140void nouveau_bo_make_global(struct nouveau_bo *); 141int nouveau_bo_wrap(struct nouveau_device *, uint32_t handle, 142 struct nouveau_bo **); 143int nouveau_bo_name_ref(struct nouveau_device *v, uint32_t name, 144 struct nouveau_bo **); 145int nouveau_bo_name_get(struct nouveau_bo *, uint32_t *name); 146void nouveau_bo_ref(struct nouveau_bo *, struct nouveau_bo **); 147int nouveau_bo_map(struct nouveau_bo *, uint32_t access, 148 struct nouveau_client *); 149int nouveau_bo_wait(struct nouveau_bo *, uint32_t access, 150 struct nouveau_client *); 151int nouveau_bo_prime_handle_ref(struct nouveau_device *, int prime_fd, 152 struct nouveau_bo **); 153int nouveau_bo_set_prime(struct nouveau_bo *, int *prime_fd); 154 155struct nouveau_list { 156 struct nouveau_list *prev; 157 struct nouveau_list *next; 158}; 159 160struct nouveau_bufref { 161 struct nouveau_list thead; 162 struct nouveau_bo *bo; 163 uint32_t packet; 164 uint32_t flags; 165 uint32_t data; 166 uint32_t vor; 167 uint32_t tor; 168 uint32_t priv_data; 169 void *priv; 170}; 171 172struct nouveau_bufctx { 173 struct nouveau_client *client; 174 struct nouveau_list head; 175 struct nouveau_list pending; 176 struct nouveau_list current; 177 int relocs; 178}; 179 180int nouveau_bufctx_new(struct nouveau_client *, int bins, 181 struct nouveau_bufctx **); 182void nouveau_bufctx_del(struct nouveau_bufctx **); 183struct nouveau_bufref * 184nouveau_bufctx_refn(struct nouveau_bufctx *, int bin, 185 struct nouveau_bo *, uint32_t flags); 186struct nouveau_bufref * 187nouveau_bufctx_mthd(struct nouveau_bufctx *, int bin, uint32_t packet, 188 struct nouveau_bo *, uint64_t data, uint32_t flags, 189 uint32_t vor, uint32_t tor); 190void nouveau_bufctx_reset(struct nouveau_bufctx *, int bin); 191 192struct nouveau_pushbuf_krec; 193struct nouveau_pushbuf { 194 struct nouveau_client *client; 195 struct nouveau_object *channel; 196 struct nouveau_bufctx *bufctx; 197 void (*kick_notify)(struct nouveau_pushbuf *); 198 void *user_priv; 199 uint32_t rsvd_kick; 200 uint32_t flags; 201 uint32_t *cur; 202 uint32_t *end; 203}; 204 205struct nouveau_pushbuf_refn { 206 struct nouveau_bo *bo; 207 uint32_t flags; 208}; 209 210int nouveau_pushbuf_new(struct nouveau_client *, struct nouveau_object *chan, 211 int nr, uint32_t size, bool immediate, 212 struct nouveau_pushbuf **); 213void nouveau_pushbuf_del(struct nouveau_pushbuf **); 214int nouveau_pushbuf_space(struct nouveau_pushbuf *, uint32_t dwords, 215 uint32_t relocs, uint32_t pushes); 216void nouveau_pushbuf_data(struct nouveau_pushbuf *, struct nouveau_bo *, 217 uint64_t offset, uint64_t length); 218int nouveau_pushbuf_refn(struct nouveau_pushbuf *, 219 struct nouveau_pushbuf_refn *, int nr); 220/* Emits a reloc into the push buffer at the current position, you *must* 221 * have previously added the referenced buffer to a buffer context, and 222 * validated it against the current push buffer. 223 */ 224void nouveau_pushbuf_reloc(struct nouveau_pushbuf *, struct nouveau_bo *, 225 uint32_t data, uint32_t flags, 226 uint32_t vor, uint32_t tor); 227int nouveau_pushbuf_validate(struct nouveau_pushbuf *); 228uint32_t nouveau_pushbuf_refd(struct nouveau_pushbuf *, struct nouveau_bo *); 229int nouveau_pushbuf_kick(struct nouveau_pushbuf *, struct nouveau_object *chan); 230struct nouveau_bufctx * 231nouveau_pushbuf_bufctx(struct nouveau_pushbuf *, struct nouveau_bufctx *); 232 233#define NOUVEAU_DEVICE_CLASS 0x80000000 234#define NOUVEAU_FIFO_CHANNEL_CLASS 0x80000001 235#define NOUVEAU_NOTIFIER_CLASS 0x80000002 236 237struct nouveau_fifo { 238 struct nouveau_object *object; 239 uint32_t channel; 240 uint32_t pushbuf; 241 uint64_t unused1[3]; 242}; 243 244struct nv04_fifo { 245 struct nouveau_fifo base; 246 uint32_t vram; 247 uint32_t gart; 248 uint32_t notify; 249}; 250 251struct nvc0_fifo { 252 struct nouveau_fifo base; 253 uint32_t notify; 254}; 255 256#define NVE0_FIFO_ENGINE_GR 0x00000001 257#define NVE0_FIFO_ENGINE_VP 0x00000002 258#define NVE0_FIFO_ENGINE_PPP 0x00000004 259#define NVE0_FIFO_ENGINE_BSP 0x00000008 260#define NVE0_FIFO_ENGINE_CE0 0x00000010 261#define NVE0_FIFO_ENGINE_CE1 0x00000020 262#define NVE0_FIFO_ENGINE_ENC 0x00000040 263 264struct nve0_fifo { 265 struct { 266 struct nouveau_fifo base; 267 uint32_t notify; 268 }; 269 uint32_t engine; 270}; 271 272struct nv04_notify { 273 struct nouveau_object *object; 274 uint32_t offset; 275 uint32_t length; 276}; 277 278bool 279nouveau_check_dead_channel(struct nouveau_drm *, struct nouveau_object *chan); 280 281#endif 282