1 /* SPDX-License-Identifier: MIT */
2 #ifndef __NVKM_ENGINE_H__
3 #define __NVKM_ENGINE_H__
4 #define nvkm_engine(p) container_of((p), struct nvkm_engine, subdev)
5 #include <core/subdev.h>
6 struct nvkm_fifo_chan;
7 struct nvkm_fb_tile;
8 
9 extern const struct nvkm_subdev_func nvkm_engine;
10 
11 struct nvkm_engine {
12 	const struct nvkm_engine_func *func;
13 	struct nvkm_subdev subdev;
14 	spinlock_t lock;
15 
16 	struct {
17 		refcount_t refcount;
18 		struct mutex mutex;
19 		bool enabled;
20 	} use;
21 };
22 
23 struct nvkm_engine_func {
24 	void *(*dtor)(struct nvkm_engine *);
25 	void (*preinit)(struct nvkm_engine *);
26 	int (*oneinit)(struct nvkm_engine *);
27 	int (*info)(struct nvkm_engine *, u64 mthd, u64 *data);
28 	int (*init)(struct nvkm_engine *);
29 	int (*fini)(struct nvkm_engine *, bool suspend);
30 	void (*intr)(struct nvkm_engine *);
31 	void (*tile)(struct nvkm_engine *, int region, struct nvkm_fb_tile *);
32 	bool (*chsw_load)(struct nvkm_engine *);
33 
34 	struct {
35 		int (*sclass)(struct nvkm_oclass *, int index,
36 			      const struct nvkm_device_oclass **);
37 	} base;
38 
39 	struct {
40 		int (*cclass)(struct nvkm_fifo_chan *,
41 			      const struct nvkm_oclass *,
42 			      struct nvkm_object **);
43 		int (*sclass)(struct nvkm_oclass *, int index);
44 	} fifo;
45 
46 	const struct nvkm_object_func *cclass;
47 	struct nvkm_sclass sclass[];
48 };
49 
50 int nvkm_engine_ctor(const struct nvkm_engine_func *, struct nvkm_device *,
51 		     enum nvkm_subdev_type, int inst, bool enable, struct nvkm_engine *);
52 int nvkm_engine_new_(const struct nvkm_engine_func *, struct nvkm_device *,
53 		     enum nvkm_subdev_type, int, bool enable, struct nvkm_engine **);
54 
55 struct nvkm_engine *nvkm_engine_ref(struct nvkm_engine *);
56 void nvkm_engine_unref(struct nvkm_engine **);
57 void nvkm_engine_tile(struct nvkm_engine *, int region);
58 bool nvkm_engine_chsw_load(struct nvkm_engine *);
59 #endif
60