blob: 83060f965244fac3f0875dd8ab34357e14dd9f12 [file] [log] [blame]
Ben Skeggs292da612011-12-09 16:11:06 +10001#ifndef __NOUVEAU_LIBDRM_PRIVATE_H__
2#define __NOUVEAU_LIBDRM_PRIVATE_H__
3
Emil Velikov42465fe2015-04-05 15:51:59 +01004#include <libdrm_macros.h>
Ben Skeggs292da612011-12-09 16:11:06 +10005#include <xf86drm.h>
6#include <xf86atomic.h>
Maarten Lankhorstb1d4def2014-03-12 22:05:15 -04007#include <pthread.h>
Ben Skeggs292da612011-12-09 16:11:06 +10008#include "nouveau_drm.h"
9
10#include "nouveau.h"
11
12#ifdef DEBUG
Emil Velikov76e97992015-03-23 21:52:00 +000013drm_private uint32_t nouveau_debug;
Ben Skeggs292da612011-12-09 16:11:06 +100014#define dbg_on(lvl) (nouveau_debug & (1 << lvl))
15#define dbg(lvl, fmt, args...) do { \
16 if (dbg_on((lvl))) \
17 fprintf(stderr, "nouveau: "fmt, ##args); \
18} while(0)
19#else
20#define dbg_on(lvl) (0)
21#define dbg(lvl, fmt, args...)
22#endif
23#define err(fmt, args...) fprintf(stderr, "nouveau: "fmt, ##args)
24
25struct nouveau_client_kref {
26 struct drm_nouveau_gem_pushbuf_bo *kref;
27 struct nouveau_pushbuf *push;
28};
29
30struct nouveau_client_priv {
31 struct nouveau_client base;
32 struct nouveau_client_kref *kref;
33 unsigned kref_nr;
34};
35
36static inline struct nouveau_client_priv *
37nouveau_client(struct nouveau_client *client)
38{
39 return (struct nouveau_client_priv *)client;
40}
41
42static inline struct drm_nouveau_gem_pushbuf_bo *
43cli_kref_get(struct nouveau_client *client, struct nouveau_bo *bo)
44{
45 struct nouveau_client_priv *pcli = nouveau_client(client);
46 struct drm_nouveau_gem_pushbuf_bo *kref = NULL;
47 if (pcli->kref_nr > bo->handle)
48 kref = pcli->kref[bo->handle].kref;
49 return kref;
50}
51
52static inline struct nouveau_pushbuf *
53cli_push_get(struct nouveau_client *client, struct nouveau_bo *bo)
54{
55 struct nouveau_client_priv *pcli = nouveau_client(client);
56 struct nouveau_pushbuf *push = NULL;
57 if (pcli->kref_nr > bo->handle)
58 push = pcli->kref[bo->handle].push;
59 return push;
60}
61
62static inline void
63cli_kref_set(struct nouveau_client *client, struct nouveau_bo *bo,
64 struct drm_nouveau_gem_pushbuf_bo *kref,
65 struct nouveau_pushbuf *push)
66{
67 struct nouveau_client_priv *pcli = nouveau_client(client);
68 if (pcli->kref_nr <= bo->handle) {
69 pcli->kref = realloc(pcli->kref,
70 sizeof(*pcli->kref) * bo->handle * 2);
71 while (pcli->kref_nr < bo->handle * 2) {
72 pcli->kref[pcli->kref_nr].kref = NULL;
73 pcli->kref[pcli->kref_nr].push = NULL;
74 pcli->kref_nr++;
75 }
76 }
77 pcli->kref[bo->handle].kref = kref;
78 pcli->kref[bo->handle].push = push;
79}
80
81struct nouveau_bo_priv {
82 struct nouveau_bo base;
83 struct nouveau_list head;
84 atomic_t refcnt;
85 uint64_t map_handle;
86 uint32_t name;
87 uint32_t access;
88};
89
90static inline struct nouveau_bo_priv *
91nouveau_bo(struct nouveau_bo *bo)
92{
93 return (struct nouveau_bo_priv *)bo;
94}
95
96struct nouveau_device_priv {
97 struct nouveau_device base;
98 int close;
Maarten Lankhorstb1d4def2014-03-12 22:05:15 -040099 pthread_mutex_t lock;
Ben Skeggs292da612011-12-09 16:11:06 +1000100 struct nouveau_list bo_list;
101 uint32_t *client;
102 int nr_client;
103 bool have_bo_usage;
Marcin Slusarzf92d7962013-03-03 22:34:38 +0100104 int gart_limit_percent, vram_limit_percent;
Ben Skeggs292da612011-12-09 16:11:06 +1000105};
106
107static inline struct nouveau_device_priv *
108nouveau_device(struct nouveau_device *dev)
109{
110 return (struct nouveau_device_priv *)dev;
111}
112
113int
114nouveau_device_open_existing(struct nouveau_device **, int, int, drm_context_t);
115
116/* abi16.c */
Ben Skeggs4a3cbf52015-11-24 09:17:52 +1000117drm_private bool abi16_object(struct nouveau_object *, int (**)(struct nouveau_object *));
118drm_private void abi16_delete(struct nouveau_object *);
Ben Skeggsf6b1b5b2015-11-24 10:10:04 +1000119drm_private int abi16_sclass(struct nouveau_object *, struct nouveau_sclass **);
Emil Velikov76e97992015-03-23 21:52:00 +0000120drm_private void abi16_bo_info(struct nouveau_bo *, struct drm_nouveau_gem_info *);
121drm_private int abi16_bo_init(struct nouveau_bo *, uint32_t alignment,
122 union nouveau_bo_config *);
Ben Skeggs292da612011-12-09 16:11:06 +1000123
124#endif