xref: /linux/drivers/gpu/drm/nouveau/include/nvkm/core/subdev.h (revision 7ae9fb1b7ecbb5d85d07857943f677fd1a559b18)
1 /* SPDX-License-Identifier: MIT */
2 #ifndef __NVKM_SUBDEV_H__
3 #define __NVKM_SUBDEV_H__
4 #include <core/device.h>
5 
6 enum nvkm_subdev_type {
7 #define NVKM_LAYOUT_ONCE(t,s,p,...) t,
8 #define NVKM_LAYOUT_INST NVKM_LAYOUT_ONCE
9 #include <core/layout.h>
10 #undef NVKM_LAYOUT_INST
11 #undef NVKM_LAYOUT_ONCE
12 	NVKM_SUBDEV_NR
13 };
14 
15 struct nvkm_subdev {
16 	const struct nvkm_subdev_func *func;
17 	struct nvkm_device *device;
18 	enum nvkm_subdev_type type;
19 	int inst;
20 
21 	char name[16];
22 	u32 debug;
23 
24 	struct {
25 		refcount_t refcount;
26 		struct mutex mutex;
27 		bool enabled;
28 	} use;
29 
30 	struct nvkm_inth inth;
31 
32 	struct list_head head;
33 	void **pself;
34 	bool oneinit;
35 };
36 
37 struct nvkm_subdev_func {
38 	void *(*dtor)(struct nvkm_subdev *);
39 	int (*preinit)(struct nvkm_subdev *);
40 	int (*oneinit)(struct nvkm_subdev *);
41 	int (*info)(struct nvkm_subdev *, u64 mthd, u64 *data);
42 	int (*init)(struct nvkm_subdev *);
43 	int (*fini)(struct nvkm_subdev *, bool suspend);
44 	void (*intr)(struct nvkm_subdev *);
45 };
46 
47 extern const char *nvkm_subdev_type[NVKM_SUBDEV_NR];
48 int nvkm_subdev_new_(const struct nvkm_subdev_func *, struct nvkm_device *, enum nvkm_subdev_type,
49 		     int inst, struct nvkm_subdev **);
50 void __nvkm_subdev_ctor(const struct nvkm_subdev_func *, struct nvkm_device *,
51 			enum nvkm_subdev_type, int inst, struct nvkm_subdev *);
52 
53 static inline void
nvkm_subdev_ctor(const struct nvkm_subdev_func * func,struct nvkm_device * device,enum nvkm_subdev_type type,int inst,struct nvkm_subdev * subdev)54 nvkm_subdev_ctor(const struct nvkm_subdev_func *func, struct nvkm_device *device,
55 		 enum nvkm_subdev_type type, int inst, struct nvkm_subdev *subdev)
56 {
57 	__nvkm_subdev_ctor(func, device, type, inst, subdev);
58 	mutex_init(&subdev->use.mutex);
59 }
60 
61 void nvkm_subdev_disable(struct nvkm_device *, enum nvkm_subdev_type, int inst);
62 void nvkm_subdev_del(struct nvkm_subdev **);
63 int  nvkm_subdev_ref(struct nvkm_subdev *);
64 void nvkm_subdev_unref(struct nvkm_subdev *);
65 int  nvkm_subdev_preinit(struct nvkm_subdev *);
66 int  nvkm_subdev_oneinit(struct nvkm_subdev *);
67 int  nvkm_subdev_init(struct nvkm_subdev *);
68 int  nvkm_subdev_fini(struct nvkm_subdev *, bool suspend);
69 int  nvkm_subdev_info(struct nvkm_subdev *, u64, u64 *);
70 void nvkm_subdev_intr(struct nvkm_subdev *);
71 
72 /* subdev logging */
73 #define nvkm_printk_ok(s,u,l)                                                                \
74 	((CONFIG_NOUVEAU_DEBUG >= (l)) && ((s)->debug >= (l) || ((u) && (u)->debug >= (l))))
75 #define nvkm_printk___(s,u,l,p,f,a...) do {                                                  \
76 	if (nvkm_printk_ok((s), (u), (l))) {                                                 \
77 		if ((u) && (u) != (s))                                                       \
78 			dev_##p((s)->device->dev, "%s(%s):"f, (s)->name, (u)->name, ##a);    \
79 		else                                                                         \
80 			dev_##p((s)->device->dev, "%s:"f, (s)->name, ##a);                   \
81 	}                                                                                    \
82 } while(0)
83 #define nvkm_printk__(s,l,p,f,a...) nvkm_printk___((s), (s), (l), p, f, ##a)
84 #define nvkm_printk_(s,l,p,f,a...) nvkm_printk__((s), (l), p, " "f, ##a)
85 #define nvkm_printk(s,l,p,f,a...) nvkm_printk_((s), NV_DBG_##l, p, f, ##a)
86 #define nvkm_fatal(s,f,a...) nvkm_printk((s), FATAL,   crit, f, ##a)
87 #define nvkm_error(s,f,a...) nvkm_printk((s), ERROR,    err, f, ##a)
88 #define nvkm_warn(s,f,a...)  nvkm_printk((s),  WARN, notice, f, ##a)
89 #define nvkm_info(s,f,a...)  nvkm_printk((s),  INFO,   info, f, ##a)
90 #define nvkm_debug(s,f,a...) nvkm_printk((s), DEBUG,   info, f, ##a)
91 #define nvkm_trace(s,f,a...) nvkm_printk((s), TRACE,   info, f, ##a)
92 #define nvkm_spam(s,f,a...)  nvkm_printk((s),  SPAM,    dbg, f, ##a)
93 
94 #define nvkm_error_ratelimited(s,f,a...) nvkm_printk((s), ERROR, err_ratelimited, f, ##a)
95 #endif
96