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