summaryrefslogtreecommitdiff
path: root/nouveau/private.h
blob: 8a5cb26144942097babcb111a789b5fd5c96e4c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#ifndef __NOUVEAU_LIBDRM_PRIVATE_H__
#define __NOUVEAU_LIBDRM_PRIVATE_H__

#include <xf86drm.h>
#include <xf86atomic.h>
#include "nouveau_drm.h"

#include "nouveau.h"

#ifdef DEBUG
uint32_t nouveau_debug;
#define dbg_on(lvl) (nouveau_debug & (1 << lvl))
#define dbg(lvl, fmt, args...) do {                                            \
	if (dbg_on((lvl)))                                                     \
		fprintf(stderr, "nouveau: "fmt, ##args);                       \
} while(0)
#else
#define dbg_on(lvl) (0)
#define dbg(lvl, fmt, args...)
#endif
#define err(fmt, args...) fprintf(stderr, "nouveau: "fmt, ##args)

struct nouveau_client_kref {
	struct drm_nouveau_gem_pushbuf_bo *kref;
	struct nouveau_pushbuf *push;
};

struct nouveau_client_priv {
	struct nouveau_client base;
	struct nouveau_client_kref *kref;
	unsigned kref_nr;
};

static inline struct nouveau_client_priv *
nouveau_client(struct nouveau_client *client)
{
	return (struct nouveau_client_priv *)client;
}

static inline struct drm_nouveau_gem_pushbuf_bo *
cli_kref_get(struct nouveau_client *client, struct nouveau_bo *bo)
{
	struct nouveau_client_priv *pcli = nouveau_client(client);
	struct drm_nouveau_gem_pushbuf_bo *kref = NULL;
	if (pcli->kref_nr > bo->handle)
		kref = pcli->kref[bo->handle].kref;
	return kref;
}

static inline struct nouveau_pushbuf *
cli_push_get(struct nouveau_client *client, struct nouveau_bo *bo)
{
	struct nouveau_client_priv *pcli = nouveau_client(client);
	struct nouveau_pushbuf *push = NULL;
	if (pcli->kref_nr > bo->handle)
		push = pcli->kref[bo->handle].push;
	return push;
}

static inline void
cli_kref_set(struct nouveau_client *client, struct nouveau_bo *bo,
	     struct drm_nouveau_gem_pushbuf_bo *kref,
	     struct nouveau_pushbuf *push)
{
	struct nouveau_client_priv *pcli = nouveau_client(client);
	if (pcli->kref_nr <= bo->handle) {
		pcli->kref = realloc(pcli->kref,
				     sizeof(*pcli->kref) * bo->handle * 2);
		while (pcli->kref_nr < bo->handle * 2) {
			pcli->kref[pcli->kref_nr].kref = NULL;
			pcli->kref[pcli->kref_nr].push = NULL;
			pcli->kref_nr++;
		}
	}
	pcli->kref[bo->handle].kref = kref;
	pcli->kref[bo->handle].push = push;
}

struct nouveau_bo_priv {
	struct nouveau_bo base;
	struct nouveau_list head;
	atomic_t refcnt;
	uint64_t map_handle;
	uint32_t name;
	uint32_t access;
};

static inline struct nouveau_bo_priv *
nouveau_bo(struct nouveau_bo *bo)
{
	return (struct nouveau_bo_priv *)bo;
}

struct nouveau_device_priv {
	struct nouveau_device base;
	int close;
	atomic_t lock;
	struct nouveau_list bo_list;
	uint32_t *client;
	int nr_client;
	bool have_bo_usage;
};

static inline struct nouveau_device_priv *
nouveau_device(struct nouveau_device *dev)
{
	return (struct nouveau_device_priv *)dev;
}

int
nouveau_device_open_existing(struct nouveau_device **, int, int, drm_context_t);

/* abi16.c */
int  abi16_chan_nv04(struct nouveau_object *);
int  abi16_chan_nvc0(struct nouveau_object *);
int  abi16_chan_nve0(struct nouveau_object *);
int  abi16_engobj(struct nouveau_object *);
int  abi16_ntfy(struct nouveau_object *);
void abi16_bo_info(struct nouveau_bo *, struct drm_nouveau_gem_info *);
int  abi16_bo_init(struct nouveau_bo *, uint32_t alignment,
		   union nouveau_bo_config *);

#endif