summaryrefslogtreecommitdiff
path: root/drm/nouveau/include/nvkm/core/subdev.h
blob: 01f2f71e6112e0b2a1e39b43b316768bfacb0083 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#ifndef __NVKM_SUBDEV_H__
#define __NVKM_SUBDEV_H__
#include <core/object.h>

#define NV_SUBDEV_(sub,var) (((var) << 8) | (sub))
#define NV_SUBDEV(name,var)  NV_SUBDEV_(NVDEV_SUBDEV_##name, (var))

struct nvkm_subdev {
	struct nvkm_object object;
	const struct nvkm_subdev_func *func;
	struct nvkm_device *device;
	int index;
	u32 pmc_enable;

	struct mutex mutex;
	u32 debug;
	bool oneinit;

	void (*intr)(struct nvkm_subdev *);
	u32 unit;
};

struct nvkm_subdev_func {
	void *(*dtor)(struct nvkm_subdev *);
	int (*preinit)(struct nvkm_subdev *);
	int (*oneinit)(struct nvkm_subdev *);
	int (*init)(struct nvkm_subdev *);
	int (*fini)(struct nvkm_subdev *, bool suspend);
	void (*intr)(struct nvkm_subdev *);
};

extern const char *nvkm_subdev_name[64];
void nvkm_subdev_ctor(const struct nvkm_subdev_func *, struct nvkm_device *,
		      int index, u32 pmc_enable, struct nvkm_subdev *);
void nvkm_subdev_del(struct nvkm_subdev **);
int  nvkm_subdev_preinit(struct nvkm_subdev *);
int  nvkm_subdev_init(struct nvkm_subdev *);
int  nvkm_subdev_fini(struct nvkm_subdev *, bool suspend);
void nvkm_subdev_intr(struct nvkm_subdev *);

static inline struct nvkm_subdev *
nv_subdev(void *obj)
{
#if CONFIG_NOUVEAU_DEBUG >= NV_DBG_PARANOIA
	BUG_ON(!nv_iclass(obj, NV_SUBDEV_CLASS));
#endif
	return obj;
}

static inline int
nv_subidx(struct nvkm_subdev *subdev)
{
	return nv_hclass(subdev) & 0xff;
}

struct nvkm_subdev *nvkm_subdev(void *obj, int idx);

#define nvkm_subdev_create(p,e,o,v,s,f,d)                                   \
	nvkm_subdev_create_((p), (e), (o), (v), (s), (f),                   \
			       sizeof(**d),(void **)d)

int  nvkm_subdev_create_(struct nvkm_object *, struct nvkm_object *,
			    struct nvkm_oclass *, u32 pclass,
			    const char *sname, const char *fname,
			    int size, void **);
void nvkm_subdev_destroy(struct nvkm_subdev *);
int  nvkm_subdev_init_old(struct nvkm_subdev *);
int  nvkm_subdev_fini_old(struct nvkm_subdev *, bool suspend);
void nvkm_subdev_reset(struct nvkm_object *);

void _nvkm_subdev_dtor(struct nvkm_object *);
int  _nvkm_subdev_init(struct nvkm_object *);
int  _nvkm_subdev_fini(struct nvkm_object *, bool suspend);

/* subdev logging */
#define nvkm_printk_(s,l,p,f,a...) do {                                        \
	struct nvkm_subdev *_subdev = (s);                                     \
	if (_subdev->debug >= (l)) {                                           \
		dev_##p(_subdev->device->dev, "%s: "f,                         \
			nvkm_subdev_name[_subdev->index], ##a);                \
	}                                                                      \
} while(0)
#define nvkm_printk(s,l,p,f,a...) nvkm_printk_((s), NV_DBG_##l, p, f, ##a)
#define nvkm_fatal(s,f,a...) nvkm_printk((s), FATAL,   crit, f, ##a)
#define nvkm_error(s,f,a...) nvkm_printk((s), ERROR,    err, f, ##a)
#define nvkm_warn(s,f,a...)  nvkm_printk((s),  WARN, notice, f, ##a)
#define nvkm_info(s,f,a...)  nvkm_printk((s),  INFO,   info, f, ##a)
#define nvkm_debug(s,f,a...) nvkm_printk((s), DEBUG,   info, f, ##a)
#define nvkm_trace(s,f,a...) nvkm_printk((s), TRACE,   info, f, ##a)
#define nvkm_spam(s,f,a...)  nvkm_printk((s),  SPAM,    dbg, f, ##a)

#include <core/engine.h>
#endif