1 #ifndef __NVKM_GPUOBJ_H__
2 #define __NVKM_GPUOBJ_H__
3 #include <core/object.h>
4 #include <core/mm.h>
5 struct nvkm_vma;
6 struct nvkm_vm;
7 
8 #define NVOBJ_FLAG_ZERO_ALLOC 0x00000001
9 #define NVOBJ_FLAG_ZERO_FREE  0x00000002
10 #define NVOBJ_FLAG_HEAP       0x00000004
11 
12 struct nvkm_gpuobj {
13 	struct nvkm_object object;
14 	struct nvkm_object *parent;
15 	struct nvkm_mm_node *node;
16 	struct nvkm_mm heap;
17 
18 	u32 flags;
19 	u64 addr;
20 	u32 size;
21 };
22 
23 static inline struct nvkm_gpuobj *
nv_gpuobj(void * obj)24 nv_gpuobj(void *obj)
25 {
26 #if CONFIG_NOUVEAU_DEBUG >= NV_DBG_PARANOIA
27 	if (unlikely(!nv_iclass(obj, NV_GPUOBJ_CLASS)))
28 		nv_assert("BAD CAST -> NvGpuObj, %08x", nv_hclass(obj));
29 #endif
30 	return obj;
31 }
32 
33 #define nvkm_gpuobj_create(p,e,c,v,g,s,a,f,d)                               \
34 	nvkm_gpuobj_create_((p), (e), (c), (v), (g), (s), (a), (f),         \
35 			       sizeof(**d), (void **)d)
36 #define nvkm_gpuobj_init(p) nvkm_object_init(&(p)->object)
37 #define nvkm_gpuobj_fini(p,s) nvkm_object_fini(&(p)->object, (s))
38 int  nvkm_gpuobj_create_(struct nvkm_object *, struct nvkm_object *,
39 			    struct nvkm_oclass *, u32 pclass,
40 			    struct nvkm_object *, u32 size, u32 align,
41 			    u32 flags, int length, void **);
42 void nvkm_gpuobj_destroy(struct nvkm_gpuobj *);
43 
44 int  nvkm_gpuobj_new(struct nvkm_object *, struct nvkm_object *, u32 size,
45 		     u32 align, u32 flags, struct nvkm_gpuobj **);
46 int  nvkm_gpuobj_dup(struct nvkm_object *, struct nvkm_gpuobj *,
47 		     struct nvkm_gpuobj **);
48 int  nvkm_gpuobj_map(struct nvkm_gpuobj *, u32 acc, struct nvkm_vma *);
49 int  nvkm_gpuobj_map_vm(struct nvkm_gpuobj *, struct nvkm_vm *, u32 access,
50 			struct nvkm_vma *);
51 void nvkm_gpuobj_unmap(struct nvkm_vma *);
52 
53 static inline void
nvkm_gpuobj_ref(struct nvkm_gpuobj * obj,struct nvkm_gpuobj ** ref)54 nvkm_gpuobj_ref(struct nvkm_gpuobj *obj, struct nvkm_gpuobj **ref)
55 {
56 	nvkm_object_ref(&obj->object, (struct nvkm_object **)ref);
57 }
58 
59 void _nvkm_gpuobj_dtor(struct nvkm_object *);
60 int  _nvkm_gpuobj_init(struct nvkm_object *);
61 int  _nvkm_gpuobj_fini(struct nvkm_object *, bool);
62 u32  _nvkm_gpuobj_rd32(struct nvkm_object *, u64);
63 void _nvkm_gpuobj_wr32(struct nvkm_object *, u64, u32);
64 #endif
65