Merge tag 'irqchip-4.7-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/maz...
[deliverable/linux.git] / drivers / gpu / drm / nouveau / nvkm / core / subdev.c
CommitLineData
9274f4a9
BS
1/*
2 * Copyright 2012 Red Hat Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 *
22 * Authors: Ben Skeggs
23 */
9274f4a9
BS
24#include <core/subdev.h>
25#include <core/device.h>
26#include <core/option.h>
6defde5a 27#include <subdev/mc.h>
9274f4a9 28
68f3f702 29static struct lock_class_key nvkm_subdev_lock_class[NVKM_SUBDEV_NR];
f0290215
BS
30
31const char *
68f3f702 32nvkm_subdev_name[NVKM_SUBDEV_NR] = {
dc06e366
MP
33 [NVKM_SUBDEV_BAR ] = "bar",
34 [NVKM_SUBDEV_VBIOS ] = "bios",
35 [NVKM_SUBDEV_BUS ] = "bus",
36 [NVKM_SUBDEV_CLK ] = "clk",
37 [NVKM_SUBDEV_DEVINIT ] = "devinit",
38 [NVKM_SUBDEV_FB ] = "fb",
39 [NVKM_SUBDEV_FUSE ] = "fuse",
40 [NVKM_SUBDEV_GPIO ] = "gpio",
41 [NVKM_SUBDEV_I2C ] = "i2c",
42 [NVKM_SUBDEV_IBUS ] = "priv",
43 [NVKM_SUBDEV_ICCSENSE] = "iccsense",
44 [NVKM_SUBDEV_INSTMEM ] = "imem",
45 [NVKM_SUBDEV_LTC ] = "ltc",
46 [NVKM_SUBDEV_MC ] = "mc",
47 [NVKM_SUBDEV_MMU ] = "mmu",
48 [NVKM_SUBDEV_MXM ] = "mxm",
49 [NVKM_SUBDEV_PCI ] = "pci",
50 [NVKM_SUBDEV_PMU ] = "pmu",
51 [NVKM_SUBDEV_SECBOOT ] = "secboot",
52 [NVKM_SUBDEV_THERM ] = "therm",
53 [NVKM_SUBDEV_TIMER ] = "tmr",
eaebfcc3 54 [NVKM_SUBDEV_TOP ] = "top",
dc06e366
MP
55 [NVKM_SUBDEV_VOLT ] = "volt",
56 [NVKM_ENGINE_BSP ] = "bsp",
57 [NVKM_ENGINE_CE0 ] = "ce0",
58 [NVKM_ENGINE_CE1 ] = "ce1",
59 [NVKM_ENGINE_CE2 ] = "ce2",
60 [NVKM_ENGINE_CIPHER ] = "cipher",
61 [NVKM_ENGINE_DISP ] = "disp",
62 [NVKM_ENGINE_DMAOBJ ] = "dma",
63 [NVKM_ENGINE_FIFO ] = "fifo",
64 [NVKM_ENGINE_GR ] = "gr",
65 [NVKM_ENGINE_IFB ] = "ifb",
66 [NVKM_ENGINE_ME ] = "me",
67 [NVKM_ENGINE_MPEG ] = "mpeg",
68 [NVKM_ENGINE_MSENC ] = "msenc",
69 [NVKM_ENGINE_MSPDEC ] = "mspdec",
70 [NVKM_ENGINE_MSPPP ] = "msppp",
71 [NVKM_ENGINE_MSVLD ] = "msvld",
294af04b
BS
72 [NVKM_ENGINE_NVENC0 ] = "nvenc0",
73 [NVKM_ENGINE_NVENC1 ] = "nvenc1",
3545b425 74 [NVKM_ENGINE_NVDEC ] = "nvdec",
dc06e366
MP
75 [NVKM_ENGINE_PM ] = "pm",
76 [NVKM_ENGINE_SEC ] = "sec",
77 [NVKM_ENGINE_SW ] = "sw",
78 [NVKM_ENGINE_VIC ] = "vic",
79 [NVKM_ENGINE_VP ] = "vp",
f0290215
BS
80};
81
82void
83nvkm_subdev_intr(struct nvkm_subdev *subdev)
84{
85 if (subdev->func->intr)
86 subdev->func->intr(subdev);
87}
88
89int
90nvkm_subdev_fini(struct nvkm_subdev *subdev, bool suspend)
91{
92 struct nvkm_device *device = subdev->device;
93 const char *action = suspend ? "suspend" : "fini";
f0290215
BS
94 s64 time;
95
96 nvkm_trace(subdev, "%s running...\n", action);
97 time = ktime_to_us(ktime_get());
98
99 if (subdev->func->fini) {
100 int ret = subdev->func->fini(subdev, suspend);
101 if (ret) {
102 nvkm_error(subdev, "%s failed, %d\n", action, ret);
103 if (suspend)
104 return ret;
105 }
106 }
107
6defde5a 108 nvkm_mc_reset(device->mc, subdev->index);
f0290215
BS
109
110 time = ktime_to_us(ktime_get()) - time;
111 nvkm_trace(subdev, "%s completed in %lldus\n", action, time);
112 return 0;
113}
114
115int
116nvkm_subdev_preinit(struct nvkm_subdev *subdev)
117{
118 s64 time;
119
120 nvkm_trace(subdev, "preinit running...\n");
121 time = ktime_to_us(ktime_get());
122
68f3f702 123 if (subdev->func->preinit) {
f0290215
BS
124 int ret = subdev->func->preinit(subdev);
125 if (ret) {
126 nvkm_error(subdev, "preinit failed, %d\n", ret);
127 return ret;
128 }
129 }
130
131 time = ktime_to_us(ktime_get()) - time;
132 nvkm_trace(subdev, "preinit completed in %lldus\n", time);
133 return 0;
134}
135
136int
137nvkm_subdev_init(struct nvkm_subdev *subdev)
138{
139 s64 time;
140 int ret;
141
142 nvkm_trace(subdev, "init running...\n");
143 time = ktime_to_us(ktime_get());
144
145 if (subdev->func->oneinit && !subdev->oneinit) {
146 s64 time;
147 nvkm_trace(subdev, "one-time init running...\n");
148 time = ktime_to_us(ktime_get());
149 ret = subdev->func->oneinit(subdev);
150 if (ret) {
151 nvkm_error(subdev, "one-time init failed, %d\n", ret);
152 return ret;
153 }
154
155 subdev->oneinit = true;
156 time = ktime_to_us(ktime_get()) - time;
157 nvkm_trace(subdev, "one-time init completed in %lldus\n", time);
158 }
159
160 if (subdev->func->init) {
161 ret = subdev->func->init(subdev);
162 if (ret) {
163 nvkm_error(subdev, "init failed, %d\n", ret);
164 return ret;
165 }
166 }
167
168 time = ktime_to_us(ktime_get()) - time;
169 nvkm_trace(subdev, "init completed in %lldus\n", time);
170 return 0;
171}
172
173void
174nvkm_subdev_del(struct nvkm_subdev **psubdev)
175{
176 struct nvkm_subdev *subdev = *psubdev;
177 s64 time;
6cf813fb 178
f0290215
BS
179 if (subdev && !WARN_ON(!subdev->func)) {
180 nvkm_trace(subdev, "destroy running...\n");
181 time = ktime_to_us(ktime_get());
182 if (subdev->func->dtor)
183 *psubdev = subdev->func->dtor(subdev);
184 time = ktime_to_us(ktime_get()) - time;
185 nvkm_trace(subdev, "destroy completed in %lldus\n", time);
186 kfree(*psubdev);
187 *psubdev = NULL;
188 }
189}
190
f0290215
BS
191void
192nvkm_subdev_ctor(const struct nvkm_subdev_func *func,
56d06fa2 193 struct nvkm_device *device, int index,
f0290215
BS
194 struct nvkm_subdev *subdev)
195{
196 const char *name = nvkm_subdev_name[index];
f0290215
BS
197 subdev->func = func;
198 subdev->device = device;
199 subdev->index = index;
f0290215
BS
200
201 __mutex_init(&subdev->mutex, name, &nvkm_subdev_lock_class[index]);
202 subdev->debug = nvkm_dbgopt(device->dbgopt, name);
203}
This page took 0.223561 seconds and 5 git commands to generate.