xref: /third_party/libdrm/nouveau/private.h (revision d722e3fb)
1#ifndef __NOUVEAU_LIBDRM_PRIVATE_H__
2#define __NOUVEAU_LIBDRM_PRIVATE_H__
3
4#include <stdio.h>
5
6#include <libdrm_macros.h>
7#include <xf86drm.h>
8#include <xf86atomic.h>
9#include <pthread.h>
10#include "nouveau_drm.h"
11
12#include "nouveau.h"
13
14/*
15 * 0x00000001 dump all pushbuffers
16 * 0x00000002 submit pushbuffers synchronously
17 * 0x80000000 if compiled with SIMULATE return -EINVAL for all pb submissions
18 */
19drm_private extern uint32_t nouveau_debug;
20drm_private extern FILE *nouveau_out;
21#define dbg_on(lvl) (nouveau_debug & (1 << lvl))
22#define dbg(lvl, fmt, args...) do {                                            \
23	if (dbg_on((lvl)))                                                     \
24		fprintf(nouveau_out, "nouveau: "fmt, ##args);                       \
25} while(0)
26#define err(fmt, args...) fprintf(nouveau_out, "nouveau: "fmt, ##args)
27
28struct nouveau_client_kref {
29	struct drm_nouveau_gem_pushbuf_bo *kref;
30	struct nouveau_pushbuf *push;
31};
32
33struct nouveau_client_priv {
34	struct nouveau_client base;
35	struct nouveau_client_kref *kref;
36	unsigned kref_nr;
37};
38
39static inline struct nouveau_client_priv *
40nouveau_client(struct nouveau_client *client)
41{
42	return (struct nouveau_client_priv *)client;
43}
44
45static inline struct drm_nouveau_gem_pushbuf_bo *
46cli_kref_get(struct nouveau_client *client, struct nouveau_bo *bo)
47{
48	struct nouveau_client_priv *pcli = nouveau_client(client);
49	struct drm_nouveau_gem_pushbuf_bo *kref = NULL;
50	if (pcli->kref_nr > bo->handle)
51		kref = pcli->kref[bo->handle].kref;
52	return kref;
53}
54
55static inline struct nouveau_pushbuf *
56cli_push_get(struct nouveau_client *client, struct nouveau_bo *bo)
57{
58	struct nouveau_client_priv *pcli = nouveau_client(client);
59	struct nouveau_pushbuf *push = NULL;
60	if (pcli->kref_nr > bo->handle)
61		push = pcli->kref[bo->handle].push;
62	return push;
63}
64
65static inline void
66cli_kref_set(struct nouveau_client *client, struct nouveau_bo *bo,
67	     struct drm_nouveau_gem_pushbuf_bo *kref,
68	     struct nouveau_pushbuf *push)
69{
70	struct nouveau_client_priv *pcli = nouveau_client(client);
71	if (pcli->kref_nr <= bo->handle) {
72		pcli->kref = realloc(pcli->kref,
73				     sizeof(*pcli->kref) * bo->handle * 2);
74		while (pcli->kref_nr < bo->handle * 2) {
75			pcli->kref[pcli->kref_nr].kref = NULL;
76			pcli->kref[pcli->kref_nr].push = NULL;
77			pcli->kref_nr++;
78		}
79	}
80	pcli->kref[bo->handle].kref = kref;
81	pcli->kref[bo->handle].push = push;
82}
83
84struct nouveau_bo_priv {
85	struct nouveau_bo base;
86	struct nouveau_list head;
87	atomic_t refcnt;
88	uint64_t map_handle;
89	uint32_t name;
90	uint32_t access;
91};
92
93static inline struct nouveau_bo_priv *
94nouveau_bo(struct nouveau_bo *bo)
95{
96	return (struct nouveau_bo_priv *)bo;
97}
98
99struct nouveau_device_priv {
100	struct nouveau_device base;
101	int close;
102	pthread_mutex_t lock;
103	struct nouveau_list bo_list;
104	uint32_t *client;
105	int nr_client;
106	bool have_bo_usage;
107	int gart_limit_percent, vram_limit_percent;
108};
109
110static inline struct nouveau_device_priv *
111nouveau_device(struct nouveau_device *dev)
112{
113	return (struct nouveau_device_priv *)dev;
114}
115
116int
117nouveau_device_open_existing(struct nouveau_device **, int, int, drm_context_t);
118
119/* abi16.c */
120drm_private bool abi16_object(struct nouveau_object *, int (**)(struct nouveau_object *));
121drm_private void abi16_delete(struct nouveau_object *);
122drm_private int  abi16_sclass(struct nouveau_object *, struct nouveau_sclass **);
123drm_private void abi16_bo_info(struct nouveau_bo *, struct drm_nouveau_gem_info *);
124drm_private int  abi16_bo_init(struct nouveau_bo *, uint32_t alignment,
125			       union nouveau_bo_config *);
126
127#endif
128