1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __NVKM_OBJECT_H__
3 #define __NVKM_OBJECT_H__
4 #include <core/oclass.h>
5 struct nvkm_event;
6 struct nvkm_gpuobj;
7 
8 struct nvkm_object {
9 	const struct nvkm_object_func *func;
10 	struct nvkm_client *client;
11 	struct nvkm_engine *engine;
12 	s32 oclass;
13 	u32 handle;
14 
15 	struct list_head head;
16 	struct list_head tree;
17 	u8  route;
18 	u64 token;
19 	u64 object;
20 	struct rb_node node;
21 };
22 
23 enum nvkm_object_map {
24 	NVKM_OBJECT_MAP_IO,
25 	NVKM_OBJECT_MAP_VA
26 };
27 
28 struct nvkm_object_func {
29 	void *(*dtor)(struct nvkm_object *);
30 	int (*init)(struct nvkm_object *);
31 	int (*fini)(struct nvkm_object *, bool suspend);
32 	int (*mthd)(struct nvkm_object *, u32 mthd, void *data, u32 size);
33 	int (*ntfy)(struct nvkm_object *, u32 mthd, struct nvkm_event **);
34 	int (*map)(struct nvkm_object *, void *argv, u32 argc,
35 		   enum nvkm_object_map *, u64 *addr, u64 *size);
36 	int (*unmap)(struct nvkm_object *);
37 	int (*rd08)(struct nvkm_object *, u64 addr, u8 *data);
38 	int (*rd16)(struct nvkm_object *, u64 addr, u16 *data);
39 	int (*rd32)(struct nvkm_object *, u64 addr, u32 *data);
40 	int (*wr08)(struct nvkm_object *, u64 addr, u8 data);
41 	int (*wr16)(struct nvkm_object *, u64 addr, u16 data);
42 	int (*wr32)(struct nvkm_object *, u64 addr, u32 data);
43 	int (*bind)(struct nvkm_object *, struct nvkm_gpuobj *, int align,
44 		    struct nvkm_gpuobj **);
45 	int (*sclass)(struct nvkm_object *, int index, struct nvkm_oclass *);
46 };
47 
48 void nvkm_object_ctor(const struct nvkm_object_func *,
49 		      const struct nvkm_oclass *, struct nvkm_object *);
50 int nvkm_object_new_(const struct nvkm_object_func *,
51 		     const struct nvkm_oclass *, void *data, u32 size,
52 		     struct nvkm_object **);
53 int nvkm_object_new(const struct nvkm_oclass *, void *data, u32 size,
54 		    struct nvkm_object **);
55 void nvkm_object_del(struct nvkm_object **);
56 void *nvkm_object_dtor(struct nvkm_object *);
57 int nvkm_object_init(struct nvkm_object *);
58 int nvkm_object_fini(struct nvkm_object *, bool suspend);
59 int nvkm_object_mthd(struct nvkm_object *, u32 mthd, void *data, u32 size);
60 int nvkm_object_ntfy(struct nvkm_object *, u32 mthd, struct nvkm_event **);
61 int nvkm_object_map(struct nvkm_object *, void *argv, u32 argc,
62 		    enum nvkm_object_map *, u64 *addr, u64 *size);
63 int nvkm_object_unmap(struct nvkm_object *);
64 int nvkm_object_rd08(struct nvkm_object *, u64 addr, u8  *data);
65 int nvkm_object_rd16(struct nvkm_object *, u64 addr, u16 *data);
66 int nvkm_object_rd32(struct nvkm_object *, u64 addr, u32 *data);
67 int nvkm_object_wr08(struct nvkm_object *, u64 addr, u8   data);
68 int nvkm_object_wr16(struct nvkm_object *, u64 addr, u16  data);
69 int nvkm_object_wr32(struct nvkm_object *, u64 addr, u32  data);
70 int nvkm_object_bind(struct nvkm_object *, struct nvkm_gpuobj *, int align,
71 		     struct nvkm_gpuobj **);
72 
73 bool nvkm_object_insert(struct nvkm_object *);
74 void nvkm_object_remove(struct nvkm_object *);
75 struct nvkm_object *nvkm_object_search(struct nvkm_client *, u64 object,
76 				       const struct nvkm_object_func *);
77 #endif
78