2 * Copyright 2012 Red Hat Inc.
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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.
24 #include <core/subdev.h>
25 #include <core/device.h>
26 #include <core/option.h>
27 #include <subdev/mc.h>
29 static struct lock_class_key nvkm_subdev_lock_class[NVKM_SUBDEV_NR];
32 nvkm_subdev_name[NVKM_SUBDEV_NR] = {
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_FAULT ] = "fault",
39 [NVKM_SUBDEV_FB ] = "fb",
40 [NVKM_SUBDEV_FUSE ] = "fuse",
41 [NVKM_SUBDEV_GPIO ] = "gpio",
42 [NVKM_SUBDEV_I2C ] = "i2c",
43 [NVKM_SUBDEV_IBUS ] = "priv",
44 [NVKM_SUBDEV_ICCSENSE] = "iccsense",
45 [NVKM_SUBDEV_INSTMEM ] = "imem",
46 [NVKM_SUBDEV_LTC ] = "ltc",
47 [NVKM_SUBDEV_MC ] = "mc",
48 [NVKM_SUBDEV_MMU ] = "mmu",
49 [NVKM_SUBDEV_MXM ] = "mxm",
50 [NVKM_SUBDEV_PCI ] = "pci",
51 [NVKM_SUBDEV_PMU ] = "pmu",
52 [NVKM_SUBDEV_SECBOOT ] = "secboot",
53 [NVKM_SUBDEV_THERM ] = "therm",
54 [NVKM_SUBDEV_TIMER ] = "tmr",
55 [NVKM_SUBDEV_TOP ] = "top",
56 [NVKM_SUBDEV_VOLT ] = "volt",
57 [NVKM_ENGINE_BSP ] = "bsp",
58 [NVKM_ENGINE_CE0 ] = "ce0",
59 [NVKM_ENGINE_CE1 ] = "ce1",
60 [NVKM_ENGINE_CE2 ] = "ce2",
61 [NVKM_ENGINE_CE3 ] = "ce3",
62 [NVKM_ENGINE_CE4 ] = "ce4",
63 [NVKM_ENGINE_CE5 ] = "ce5",
64 [NVKM_ENGINE_CE6 ] = "ce6",
65 [NVKM_ENGINE_CE7 ] = "ce7",
66 [NVKM_ENGINE_CE8 ] = "ce8",
67 [NVKM_ENGINE_CIPHER ] = "cipher",
68 [NVKM_ENGINE_DISP ] = "disp",
69 [NVKM_ENGINE_DMAOBJ ] = "dma",
70 [NVKM_ENGINE_FIFO ] = "fifo",
71 [NVKM_ENGINE_GR ] = "gr",
72 [NVKM_ENGINE_IFB ] = "ifb",
73 [NVKM_ENGINE_ME ] = "me",
74 [NVKM_ENGINE_MPEG ] = "mpeg",
75 [NVKM_ENGINE_MSENC ] = "msenc",
76 [NVKM_ENGINE_MSPDEC ] = "mspdec",
77 [NVKM_ENGINE_MSPPP ] = "msppp",
78 [NVKM_ENGINE_MSVLD ] = "msvld",
79 [NVKM_ENGINE_NVENC0 ] = "nvenc0",
80 [NVKM_ENGINE_NVENC1 ] = "nvenc1",
81 [NVKM_ENGINE_NVENC2 ] = "nvenc2",
82 [NVKM_ENGINE_NVDEC ] = "nvdec",
83 [NVKM_ENGINE_PM ] = "pm",
84 [NVKM_ENGINE_SEC ] = "sec",
85 [NVKM_ENGINE_SEC2 ] = "sec2",
86 [NVKM_ENGINE_SW ] = "sw",
87 [NVKM_ENGINE_VIC ] = "vic",
88 [NVKM_ENGINE_VP ] = "vp",
92 nvkm_subdev_intr(struct nvkm_subdev *subdev)
94 if (subdev->func->intr)
95 subdev->func->intr(subdev);
99 nvkm_subdev_info(struct nvkm_subdev *subdev, u64 mthd, u64 *data)
101 if (subdev->func->info)
102 return subdev->func->info(subdev, mthd, data);
107 nvkm_subdev_fini(struct nvkm_subdev *subdev, bool suspend)
109 struct nvkm_device *device = subdev->device;
110 const char *action = suspend ? "suspend" : "fini";
113 nvkm_trace(subdev, "%s running...\n", action);
114 time = ktime_to_us(ktime_get());
116 if (subdev->func->fini) {
117 int ret = subdev->func->fini(subdev, suspend);
119 nvkm_error(subdev, "%s failed, %d\n", action, ret);
125 nvkm_mc_reset(device, subdev->index);
127 time = ktime_to_us(ktime_get()) - time;
128 nvkm_trace(subdev, "%s completed in %lldus\n", action, time);
133 nvkm_subdev_preinit(struct nvkm_subdev *subdev)
137 nvkm_trace(subdev, "preinit running...\n");
138 time = ktime_to_us(ktime_get());
140 if (subdev->func->preinit) {
141 int ret = subdev->func->preinit(subdev);
143 nvkm_error(subdev, "preinit failed, %d\n", ret);
148 time = ktime_to_us(ktime_get()) - time;
149 nvkm_trace(subdev, "preinit completed in %lldus\n", time);
154 nvkm_subdev_init(struct nvkm_subdev *subdev)
159 nvkm_trace(subdev, "init running...\n");
160 time = ktime_to_us(ktime_get());
162 if (subdev->func->oneinit && !subdev->oneinit) {
164 nvkm_trace(subdev, "one-time init running...\n");
165 time = ktime_to_us(ktime_get());
166 ret = subdev->func->oneinit(subdev);
168 nvkm_error(subdev, "one-time init failed, %d\n", ret);
172 subdev->oneinit = true;
173 time = ktime_to_us(ktime_get()) - time;
174 nvkm_trace(subdev, "one-time init completed in %lldus\n", time);
177 if (subdev->func->init) {
178 ret = subdev->func->init(subdev);
180 nvkm_error(subdev, "init failed, %d\n", ret);
185 time = ktime_to_us(ktime_get()) - time;
186 nvkm_trace(subdev, "init completed in %lldus\n", time);
191 nvkm_subdev_del(struct nvkm_subdev **psubdev)
193 struct nvkm_subdev *subdev = *psubdev;
196 if (subdev && !WARN_ON(!subdev->func)) {
197 nvkm_trace(subdev, "destroy running...\n");
198 time = ktime_to_us(ktime_get());
199 if (subdev->func->dtor)
200 *psubdev = subdev->func->dtor(subdev);
201 time = ktime_to_us(ktime_get()) - time;
202 nvkm_trace(subdev, "destroy completed in %lldus\n", time);
209 nvkm_subdev_ctor(const struct nvkm_subdev_func *func,
210 struct nvkm_device *device, int index,
211 struct nvkm_subdev *subdev)
213 const char *name = nvkm_subdev_name[index];
215 subdev->device = device;
216 subdev->index = index;
218 __mutex_init(&subdev->mutex, name, &nvkm_subdev_lock_class[index]);
219 subdev->debug = nvkm_dbgopt(device->dbgopt, name);