drm/nouveau/core: prepare for new-style objects
[deliverable/linux.git] / drivers / gpu / drm / nouveau / include / nvkm / core / subdev.h
1 #ifndef __NVKM_SUBDEV_H__
2 #define __NVKM_SUBDEV_H__
3 #include <core/object.h>
4
5 #define NV_SUBDEV_(sub,var) (((var) << 8) | (sub))
6 #define NV_SUBDEV(name,var) NV_SUBDEV_(NVDEV_SUBDEV_##name, (var))
7
8 struct nvkm_subdev {
9 struct nvkm_object object;
10 const struct nvkm_subdev_func *func;
11 struct nvkm_device *device;
12 int index;
13 u32 pmc_enable;
14
15 struct mutex mutex;
16 u32 debug;
17 bool oneinit;
18
19 void (*intr)(struct nvkm_subdev *);
20 u32 unit;
21 };
22
23 struct nvkm_subdev_func {
24 void *(*dtor)(struct nvkm_subdev *);
25 int (*preinit)(struct nvkm_subdev *);
26 int (*oneinit)(struct nvkm_subdev *);
27 int (*init)(struct nvkm_subdev *);
28 int (*fini)(struct nvkm_subdev *, bool suspend);
29 void (*intr)(struct nvkm_subdev *);
30 };
31
32 extern const char *nvkm_subdev_name[64];
33 void nvkm_subdev_ctor(const struct nvkm_subdev_func *, struct nvkm_device *,
34 int index, u32 pmc_enable, struct nvkm_subdev *);
35 void nvkm_subdev_del(struct nvkm_subdev **);
36 int nvkm_subdev_preinit(struct nvkm_subdev *);
37 int nvkm_subdev_init(struct nvkm_subdev *);
38 int nvkm_subdev_fini(struct nvkm_subdev *, bool suspend);
39 void nvkm_subdev_intr(struct nvkm_subdev *);
40
41 static inline struct nvkm_subdev *
42 nv_subdev(void *obj)
43 {
44 #if CONFIG_NOUVEAU_DEBUG >= NV_DBG_PARANOIA
45 BUG_ON(!nv_iclass(obj, NV_SUBDEV_CLASS));
46 #endif
47 return obj;
48 }
49
50 static inline int
51 nv_subidx(struct nvkm_subdev *subdev)
52 {
53 return nv_hclass(subdev) & 0xff;
54 }
55
56 struct nvkm_subdev *nvkm_subdev(void *obj, int idx);
57
58 #define nvkm_subdev_create(p,e,o,v,s,f,d) \
59 nvkm_subdev_create_((p), (e), (o), (v), (s), (f), \
60 sizeof(**d),(void **)d)
61
62 int nvkm_subdev_create_(struct nvkm_object *, struct nvkm_object *,
63 struct nvkm_oclass *, u32 pclass,
64 const char *sname, const char *fname,
65 int size, void **);
66 void nvkm_subdev_destroy(struct nvkm_subdev *);
67 int nvkm_subdev_init_old(struct nvkm_subdev *);
68 int nvkm_subdev_fini_old(struct nvkm_subdev *, bool suspend);
69 void nvkm_subdev_reset(struct nvkm_object *);
70
71 void _nvkm_subdev_dtor(struct nvkm_object *);
72 int _nvkm_subdev_init(struct nvkm_object *);
73 int _nvkm_subdev_fini(struct nvkm_object *, bool suspend);
74
75 /* subdev logging */
76 #define nvkm_printk_(s,l,p,f,a...) do { \
77 struct nvkm_subdev *_subdev = (s); \
78 if (_subdev->debug >= (l)) { \
79 dev_##p(_subdev->device->dev, "%s: "f, \
80 nvkm_subdev_name[_subdev->index], ##a); \
81 } \
82 } while(0)
83 #define nvkm_printk(s,l,p,f,a...) nvkm_printk_((s), NV_DBG_##l, p, f, ##a)
84 #define nvkm_fatal(s,f,a...) nvkm_printk((s), FATAL, crit, f, ##a)
85 #define nvkm_error(s,f,a...) nvkm_printk((s), ERROR, err, f, ##a)
86 #define nvkm_warn(s,f,a...) nvkm_printk((s), WARN, notice, f, ##a)
87 #define nvkm_info(s,f,a...) nvkm_printk((s), INFO, info, f, ##a)
88 #define nvkm_debug(s,f,a...) nvkm_printk((s), DEBUG, info, f, ##a)
89 #define nvkm_trace(s,f,a...) nvkm_printk((s), TRACE, info, f, ##a)
90 #define nvkm_spam(s,f,a...) nvkm_printk((s), SPAM, dbg, f, ##a)
91
92 #include <core/engine.h>
93 #endif
This page took 0.042841 seconds and 5 git commands to generate.