aboutsummaryrefslogtreecommitdiff
path: root/drivers/gpu/drm/nouveau/include/nvkm/core/subdev.h
blob: 6fdc39116aac9a6152a95ad38ca7e4e4321d995b (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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#ifndef __NVKM_SUBDEV_H__
#define __NVKM_SUBDEV_H__
#include <core/object.h>
#include <core/devidx.h>

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

struct nvkm_subdev {
	struct nvkm_object object;
	struct mutex mutex;
	const char *name;
	void __iomem *mmio;
	u32 debug;
	u32 unit;

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

static inline struct nvkm_subdev *
nv_subdev(void *obj)
{
#if CONFIG_NOUVEAU_DEBUG >= NV_DBG_PARANOIA
	if (unlikely(!nv_iclass(obj, NV_SUBDEV_CLASS)))
		nv_assert("BAD CAST -> NvSubDev, %08x", nv_hclass(obj));
#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(struct nvkm_subdev *);
int  nvkm_subdev_fini(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);

#define s_printk(s,l,f,a...) do {                                              \
	if ((s)->debug >= OS_DBG_##l) {                                        \
		nv_printk((s)->base.parent, (s)->name, l, f, ##a);             \
	}                                                                      \
} while(0)

static inline u8
nv_rd08(void *obj, u32 addr)
{
	struct nvkm_subdev *subdev = nv_subdev(obj);
	u8 data = ioread8(subdev->mmio + addr);
	nv_spam(subdev, "nv_rd08 0x%06x 0x%02x\n", addr, data);
	return data;
}

static inline u16
nv_rd16(void *obj, u32 addr)
{
	struct nvkm_subdev *subdev = nv_subdev(obj);
	u16 data = ioread16_native(subdev->mmio + addr);
	nv_spam(subdev, "nv_rd16 0x%06x 0x%04x\n", addr, data);
	return data;
}

static inline u32
nv_rd32(void *obj, u32 addr)
{
	struct nvkm_subdev *subdev = nv_subdev(obj);
	u32 data = ioread32_native(subdev->mmio + addr);
	nv_spam(subdev, "nv_rd32 0x%06x 0x%08x\n", addr, data);
	return data;
}

static inline void
nv_wr08(void *obj, u32 addr, u8 data)
{
	struct nvkm_subdev *subdev = nv_subdev(obj);
	nv_spam(subdev, "nv_wr08 0x%06x 0x%02x\n", addr, data);
	iowrite8(data, subdev->mmio + addr);
}

static inline void
nv_wr16(void *obj, u32 addr, u16 data)
{
	struct nvkm_subdev *subdev = nv_subdev(obj);
	nv_spam(subdev, "nv_wr16 0x%06x 0x%04x\n", addr, data);
	iowrite16_native(data, subdev->mmio + addr);
}

static inline void
nv_wr32(void *obj, u32 addr, u32 data)
{
	struct nvkm_subdev *subdev = nv_subdev(obj);
	nv_spam(subdev, "nv_wr32 0x%06x 0x%08x\n", addr, data);
	iowrite32_native(data, subdev->mmio + addr);
}

static inline u32
nv_mask(void *obj, u32 addr, u32 mask, u32 data)
{
	u32 temp = nv_rd32(obj, addr);
	nv_wr32(obj, addr, (temp & ~mask) | data);
	return temp;
}
#endif