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