blob: 60714b8efaf8fb9c944f6a112108542de72d6844 [file] [log] [blame]
Ben Skeggs292da612011-12-09 16:11:06 +10001#ifndef __NOUVEAU_LIBDRM_PRIVATE_H__
2#define __NOUVEAU_LIBDRM_PRIVATE_H__
3
4#include <xf86drm.h>
5#include <xf86atomic.h>
6#include "nouveau_drm.h"
7
8#include "nouveau.h"
9
10#ifdef DEBUG
11uint32_t nouveau_debug;
12#define dbg_on(lvl) (nouveau_debug & (1 << lvl))
13#define dbg(lvl, fmt, args...) do { \
14 if (dbg_on((lvl))) \
15 fprintf(stderr, "nouveau: "fmt, ##args); \
16} while(0)
17#else
18#define dbg_on(lvl) (0)
19#define dbg(lvl, fmt, args...)
20#endif
21#define err(fmt, args...) fprintf(stderr, "nouveau: "fmt, ##args)
22
23struct nouveau_client_kref {
24 struct drm_nouveau_gem_pushbuf_bo *kref;
25 struct nouveau_pushbuf *push;
26};
27
28struct nouveau_client_priv {
29 struct nouveau_client base;
30 struct nouveau_client_kref *kref;
31 unsigned kref_nr;
32};
33
34static inline struct nouveau_client_priv *
35nouveau_client(struct nouveau_client *client)
36{
37 return (struct nouveau_client_priv *)client;
38}
39
40static inline struct drm_nouveau_gem_pushbuf_bo *
41cli_kref_get(struct nouveau_client *client, struct nouveau_bo *bo)
42{
43 struct nouveau_client_priv *pcli = nouveau_client(client);
44 struct drm_nouveau_gem_pushbuf_bo *kref = NULL;
45 if (pcli->kref_nr > bo->handle)
46 kref = pcli->kref[bo->handle].kref;
47 return kref;
48}
49
50static inline struct nouveau_pushbuf *
51cli_push_get(struct nouveau_client *client, struct nouveau_bo *bo)
52{
53 struct nouveau_client_priv *pcli = nouveau_client(client);
54 struct nouveau_pushbuf *push = NULL;
55 if (pcli->kref_nr > bo->handle)
56 push = pcli->kref[bo->handle].push;
57 return push;
58}
59
60static inline void
61cli_kref_set(struct nouveau_client *client, struct nouveau_bo *bo,
62 struct drm_nouveau_gem_pushbuf_bo *kref,
63 struct nouveau_pushbuf *push)
64{
65 struct nouveau_client_priv *pcli = nouveau_client(client);
66 if (pcli->kref_nr <= bo->handle) {
67 pcli->kref = realloc(pcli->kref,
68 sizeof(*pcli->kref) * bo->handle * 2);
69 while (pcli->kref_nr < bo->handle * 2) {
70 pcli->kref[pcli->kref_nr].kref = NULL;
71 pcli->kref[pcli->kref_nr].push = NULL;
72 pcli->kref_nr++;
73 }
74 }
75 pcli->kref[bo->handle].kref = kref;
76 pcli->kref[bo->handle].push = push;
77}
78
79struct nouveau_bo_priv {
80 struct nouveau_bo base;
81 struct nouveau_list head;
82 atomic_t refcnt;
83 uint64_t map_handle;
84 uint32_t name;
85 uint32_t access;
86};
87
88static inline struct nouveau_bo_priv *
89nouveau_bo(struct nouveau_bo *bo)
90{
91 return (struct nouveau_bo_priv *)bo;
92}
93
94struct nouveau_device_priv {
95 struct nouveau_device base;
96 int close;
97 atomic_t lock;
98 struct nouveau_list bo_list;
99 uint32_t *client;
100 int nr_client;
101 bool have_bo_usage;
Marcin Slusarzf92d7962013-03-03 22:34:38 +0100102 int gart_limit_percent, vram_limit_percent;
Ben Skeggs292da612011-12-09 16:11:06 +1000103};
104
105static inline struct nouveau_device_priv *
106nouveau_device(struct nouveau_device *dev)
107{
108 return (struct nouveau_device_priv *)dev;
109}
110
111int
112nouveau_device_open_existing(struct nouveau_device **, int, int, drm_context_t);
113
114/* abi16.c */
115int abi16_chan_nv04(struct nouveau_object *);
116int abi16_chan_nvc0(struct nouveau_object *);
Ben Skeggsc41b4942012-11-23 12:40:30 +1000117int abi16_chan_nve0(struct nouveau_object *);
Ben Skeggs292da612011-12-09 16:11:06 +1000118int abi16_engobj(struct nouveau_object *);
119int abi16_ntfy(struct nouveau_object *);
120void abi16_bo_info(struct nouveau_bo *, struct drm_nouveau_gem_info *);
121int abi16_bo_init(struct nouveau_bo *, uint32_t alignment,
122 union nouveau_bo_config *);
123
124#endif