summaryrefslogtreecommitdiff
path: root/drivers/gpu/drm/nouveau/nvkm/core/subdev.c
blob: c61b467cf45e1c738dfc66670128d396f01fd4e3 (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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
/*
 * Copyright 2012 Red Hat Inc.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 *
 * Authors: Ben Skeggs
 */
#include <core/subdev.h>
#include <core/device.h>
#include <core/option.h>
#include <subdev/mc.h>

static struct lock_class_key nvkm_subdev_lock_class[NVKM_SUBDEV_NR];

const char *
nvkm_subdev_name[NVKM_SUBDEV_NR] = {
	[NVKM_SUBDEV_BAR     ] = "bar",
	[NVKM_SUBDEV_VBIOS   ] = "bios",
	[NVKM_SUBDEV_BUS     ] = "bus",
	[NVKM_SUBDEV_CLK     ] = "clk",
	[NVKM_SUBDEV_DEVINIT ] = "devinit",
	[NVKM_SUBDEV_FAULT   ] = "fault",
	[NVKM_SUBDEV_FB      ] = "fb",
	[NVKM_SUBDEV_FUSE    ] = "fuse",
	[NVKM_SUBDEV_GPIO    ] = "gpio",
	[NVKM_SUBDEV_I2C     ] = "i2c",
	[NVKM_SUBDEV_IBUS    ] = "priv",
	[NVKM_SUBDEV_ICCSENSE] = "iccsense",
	[NVKM_SUBDEV_INSTMEM ] = "imem",
	[NVKM_SUBDEV_LTC     ] = "ltc",
	[NVKM_SUBDEV_MC      ] = "mc",
	[NVKM_SUBDEV_MMU     ] = "mmu",
	[NVKM_SUBDEV_MXM     ] = "mxm",
	[NVKM_SUBDEV_PCI     ] = "pci",
	[NVKM_SUBDEV_PMU     ] = "pmu",
	[NVKM_SUBDEV_SECBOOT ] = "secboot",
	[NVKM_SUBDEV_THERM   ] = "therm",
	[NVKM_SUBDEV_TIMER   ] = "tmr",
	[NVKM_SUBDEV_TOP     ] = "top",
	[NVKM_SUBDEV_VOLT    ] = "volt",
	[NVKM_ENGINE_BSP     ] = "bsp",
	[NVKM_ENGINE_CE0     ] = "ce0",
	[NVKM_ENGINE_CE1     ] = "ce1",
	[NVKM_ENGINE_CE2     ] = "ce2",
	[NVKM_ENGINE_CE3     ] = "ce3",
	[NVKM_ENGINE_CE4     ] = "ce4",
	[NVKM_ENGINE_CE5     ] = "ce5",
	[NVKM_ENGINE_CE6     ] = "ce6",
	[NVKM_ENGINE_CE7     ] = "ce7",
	[NVKM_ENGINE_CE8     ] = "ce8",
	[NVKM_ENGINE_CIPHER  ] = "cipher",
	[NVKM_ENGINE_DISP    ] = "disp",
	[NVKM_ENGINE_DMAOBJ  ] = "dma",
	[NVKM_ENGINE_FIFO    ] = "fifo",
	[NVKM_ENGINE_GR      ] = "gr",
	[NVKM_ENGINE_IFB     ] = "ifb",
	[NVKM_ENGINE_ME      ] = "me",
	[NVKM_ENGINE_MPEG    ] = "mpeg",
	[NVKM_ENGINE_MSENC   ] = "msenc",
	[NVKM_ENGINE_MSPDEC  ] = "mspdec",
	[NVKM_ENGINE_MSPPP   ] = "msppp",
	[NVKM_ENGINE_MSVLD   ] = "msvld",
	[NVKM_ENGINE_NVENC0  ] = "nvenc0",
	[NVKM_ENGINE_NVENC1  ] = "nvenc1",
	[NVKM_ENGINE_NVENC2  ] = "nvenc2",
	[NVKM_ENGINE_NVDEC0  ] = "nvdec0",
	[NVKM_ENGINE_NVDEC1  ] = "nvdec1",
	[NVKM_ENGINE_NVDEC2  ] = "nvdec2",
	[NVKM_ENGINE_PM      ] = "pm",
	[NVKM_ENGINE_SEC     ] = "sec",
	[NVKM_ENGINE_SEC2    ] = "sec2",
	[NVKM_ENGINE_SW      ] = "sw",
	[NVKM_ENGINE_VIC     ] = "vic",
	[NVKM_ENGINE_VP      ] = "vp",
};

void
nvkm_subdev_intr(struct nvkm_subdev *subdev)
{
	if (subdev->func->intr)
		subdev->func->intr(subdev);
}

int
nvkm_subdev_info(struct nvkm_subdev *subdev, u64 mthd, u64 *data)
{
	if (subdev->func->info)
		return subdev->func->info(subdev, mthd, data);
	return -ENOSYS;
}

int
nvkm_subdev_fini(struct nvkm_subdev *subdev, bool suspend)
{
	struct nvkm_device *device = subdev->device;
	const char *action = suspend ? "suspend" : "fini";
	s64 time;

	nvkm_trace(subdev, "%s running...\n", action);
	time = ktime_to_us(ktime_get());

	if (subdev->func->fini) {
		int ret = subdev->func->fini(subdev, suspend);
		if (ret) {
			nvkm_error(subdev, "%s failed, %d\n", action, ret);
			if (suspend)
				return ret;
		}
	}

	nvkm_mc_reset(device, subdev->index);

	time = ktime_to_us(ktime_get()) - time;
	nvkm_trace(subdev, "%s completed in %lldus\n", action, time);
	return 0;
}

int
nvkm_subdev_preinit(struct nvkm_subdev *subdev)
{
	s64 time;

	nvkm_trace(subdev, "preinit running...\n");
	time = ktime_to_us(ktime_get());

	if (subdev->func->preinit) {
		int ret = subdev->func->preinit(subdev);
		if (ret) {
			nvkm_error(subdev, "preinit failed, %d\n", ret);
			return ret;
		}
	}

	time = ktime_to_us(ktime_get()) - time;
	nvkm_trace(subdev, "preinit completed in %lldus\n", time);
	return 0;
}

int
nvkm_subdev_init(struct nvkm_subdev *subdev)
{
	s64 time;
	int ret;

	nvkm_trace(subdev, "init running...\n");
	time = ktime_to_us(ktime_get());

	if (subdev->func->oneinit && !subdev->oneinit) {
		s64 time;
		nvkm_trace(subdev, "one-time init running...\n");
		time = ktime_to_us(ktime_get());
		ret = subdev->func->oneinit(subdev);
		if (ret) {
			nvkm_error(subdev, "one-time init failed, %d\n", ret);
			return ret;
		}

		subdev->oneinit = true;
		time = ktime_to_us(ktime_get()) - time;
		nvkm_trace(subdev, "one-time init completed in %lldus\n", time);
	}

	if (subdev->func->init) {
		ret = subdev->func->init(subdev);
		if (ret) {
			nvkm_error(subdev, "init failed, %d\n", ret);
			return ret;
		}
	}

	time = ktime_to_us(ktime_get()) - time;
	nvkm_trace(subdev, "init completed in %lldus\n", time);
	return 0;
}

void
nvkm_subdev_del(struct nvkm_subdev **psubdev)
{
	struct nvkm_subdev *subdev = *psubdev;
	s64 time;

	if (subdev && !WARN_ON(!subdev->func)) {
		nvkm_trace(subdev, "destroy running...\n");
		time = ktime_to_us(ktime_get());
		if (subdev->func->dtor)
			*psubdev = subdev->func->dtor(subdev);
		time = ktime_to_us(ktime_get()) - time;
		nvkm_trace(subdev, "destroy completed in %lldus\n", time);
		kfree(*psubdev);
		*psubdev = NULL;
	}
}

void
nvkm_subdev_ctor(const struct nvkm_subdev_func *func,
		 struct nvkm_device *device, int index,
		 struct nvkm_subdev *subdev)
{
	const char *name = nvkm_subdev_name[index];
	subdev->func = func;
	subdev->device = device;
	subdev->index = index;

	__mutex_init(&subdev->mutex, name, &nvkm_subdev_lock_class[index]);
	subdev->debug = nvkm_dbgopt(device->dbgopt, name);
}