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