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_ACR
] = "acr",
34 [NVKM_SUBDEV_BAR
] = "bar",
35 [NVKM_SUBDEV_VBIOS
] = "bios",
36 [NVKM_SUBDEV_BUS
] = "bus",
37 [NVKM_SUBDEV_CLK
] = "clk",
38 [NVKM_SUBDEV_DEVINIT
] = "devinit",
39 [NVKM_SUBDEV_FAULT
] = "fault",
40 [NVKM_SUBDEV_FB
] = "fb",
41 [NVKM_SUBDEV_FUSE
] = "fuse",
42 [NVKM_SUBDEV_GPIO
] = "gpio",
43 [NVKM_SUBDEV_GSP
] = "gsp",
44 [NVKM_SUBDEV_I2C
] = "i2c",
45 [NVKM_SUBDEV_IBUS
] = "priv",
46 [NVKM_SUBDEV_ICCSENSE
] = "iccsense",
47 [NVKM_SUBDEV_INSTMEM
] = "imem",
48 [NVKM_SUBDEV_LTC
] = "ltc",
49 [NVKM_SUBDEV_MC
] = "mc",
50 [NVKM_SUBDEV_MMU
] = "mmu",
51 [NVKM_SUBDEV_MXM
] = "mxm",
52 [NVKM_SUBDEV_PCI
] = "pci",
53 [NVKM_SUBDEV_PMU
] = "pmu",
54 [NVKM_SUBDEV_THERM
] = "therm",
55 [NVKM_SUBDEV_TIMER
] = "tmr",
56 [NVKM_SUBDEV_TOP
] = "top",
57 [NVKM_SUBDEV_VOLT
] = "volt",
58 [NVKM_ENGINE_BSP
] = "bsp",
59 [NVKM_ENGINE_CE0
] = "ce0",
60 [NVKM_ENGINE_CE1
] = "ce1",
61 [NVKM_ENGINE_CE2
] = "ce2",
62 [NVKM_ENGINE_CE3
] = "ce3",
63 [NVKM_ENGINE_CE4
] = "ce4",
64 [NVKM_ENGINE_CE5
] = "ce5",
65 [NVKM_ENGINE_CE6
] = "ce6",
66 [NVKM_ENGINE_CE7
] = "ce7",
67 [NVKM_ENGINE_CE8
] = "ce8",
68 [NVKM_ENGINE_CIPHER
] = "cipher",
69 [NVKM_ENGINE_DISP
] = "disp",
70 [NVKM_ENGINE_DMAOBJ
] = "dma",
71 [NVKM_ENGINE_FIFO
] = "fifo",
72 [NVKM_ENGINE_GR
] = "gr",
73 [NVKM_ENGINE_IFB
] = "ifb",
74 [NVKM_ENGINE_ME
] = "me",
75 [NVKM_ENGINE_MPEG
] = "mpeg",
76 [NVKM_ENGINE_MSENC
] = "msenc",
77 [NVKM_ENGINE_MSPDEC
] = "mspdec",
78 [NVKM_ENGINE_MSPPP
] = "msppp",
79 [NVKM_ENGINE_MSVLD
] = "msvld",
80 [NVKM_ENGINE_NVENC0
] = "nvenc0",
81 [NVKM_ENGINE_NVENC1
] = "nvenc1",
82 [NVKM_ENGINE_NVENC2
] = "nvenc2",
83 [NVKM_ENGINE_NVDEC0
] = "nvdec0",
84 [NVKM_ENGINE_NVDEC1
] = "nvdec1",
85 [NVKM_ENGINE_NVDEC2
] = "nvdec2",
86 [NVKM_ENGINE_PM
] = "pm",
87 [NVKM_ENGINE_SEC
] = "sec",
88 [NVKM_ENGINE_SEC2
] = "sec2",
89 [NVKM_ENGINE_SW
] = "sw",
90 [NVKM_ENGINE_VIC
] = "vic",
91 [NVKM_ENGINE_VP
] = "vp",
95 nvkm_subdev_intr(struct nvkm_subdev
*subdev
)
97 if (subdev
->func
->intr
)
98 subdev
->func
->intr(subdev
);
102 nvkm_subdev_info(struct nvkm_subdev
*subdev
, u64 mthd
, u64
*data
)
104 if (subdev
->func
->info
)
105 return subdev
->func
->info(subdev
, mthd
, data
);
110 nvkm_subdev_fini(struct nvkm_subdev
*subdev
, bool suspend
)
112 struct nvkm_device
*device
= subdev
->device
;
113 const char *action
= suspend
? "suspend" : "fini";
116 nvkm_trace(subdev
, "%s running...\n", action
);
117 time
= ktime_to_us(ktime_get());
119 if (subdev
->func
->fini
) {
120 int ret
= subdev
->func
->fini(subdev
, suspend
);
122 nvkm_error(subdev
, "%s failed, %d\n", action
, ret
);
128 nvkm_mc_reset(device
, subdev
->index
);
130 time
= ktime_to_us(ktime_get()) - time
;
131 nvkm_trace(subdev
, "%s completed in %lldus\n", action
, time
);
136 nvkm_subdev_preinit(struct nvkm_subdev
*subdev
)
140 nvkm_trace(subdev
, "preinit running...\n");
141 time
= ktime_to_us(ktime_get());
143 if (subdev
->func
->preinit
) {
144 int ret
= subdev
->func
->preinit(subdev
);
146 nvkm_error(subdev
, "preinit failed, %d\n", ret
);
151 time
= ktime_to_us(ktime_get()) - time
;
152 nvkm_trace(subdev
, "preinit completed in %lldus\n", time
);
157 nvkm_subdev_init(struct nvkm_subdev
*subdev
)
162 nvkm_trace(subdev
, "init running...\n");
163 time
= ktime_to_us(ktime_get());
165 if (subdev
->func
->oneinit
&& !subdev
->oneinit
) {
167 nvkm_trace(subdev
, "one-time init running...\n");
168 time
= ktime_to_us(ktime_get());
169 ret
= subdev
->func
->oneinit(subdev
);
171 nvkm_error(subdev
, "one-time init failed, %d\n", ret
);
175 subdev
->oneinit
= true;
176 time
= ktime_to_us(ktime_get()) - time
;
177 nvkm_trace(subdev
, "one-time init completed in %lldus\n", time
);
180 if (subdev
->func
->init
) {
181 ret
= subdev
->func
->init(subdev
);
183 nvkm_error(subdev
, "init failed, %d\n", ret
);
188 time
= ktime_to_us(ktime_get()) - time
;
189 nvkm_trace(subdev
, "init completed in %lldus\n", time
);
194 nvkm_subdev_del(struct nvkm_subdev
**psubdev
)
196 struct nvkm_subdev
*subdev
= *psubdev
;
199 if (subdev
&& !WARN_ON(!subdev
->func
)) {
200 nvkm_trace(subdev
, "destroy running...\n");
201 time
= ktime_to_us(ktime_get());
202 if (subdev
->func
->dtor
)
203 *psubdev
= subdev
->func
->dtor(subdev
);
204 time
= ktime_to_us(ktime_get()) - time
;
205 nvkm_trace(subdev
, "destroy completed in %lldus\n", time
);
212 nvkm_subdev_ctor(const struct nvkm_subdev_func
*func
,
213 struct nvkm_device
*device
, int index
,
214 struct nvkm_subdev
*subdev
)
216 const char *name
= nvkm_subdev_name
[index
];
218 subdev
->device
= device
;
219 subdev
->index
= index
;
221 __mutex_init(&subdev
->mutex
, name
, &nvkm_subdev_lock_class
[index
]);
222 subdev
->debug
= nvkm_dbgopt(device
->dbgopt
, name
);
226 nvkm_subdev_new_(const struct nvkm_subdev_func
*func
,
227 struct nvkm_device
*device
, int index
,
228 struct nvkm_subdev
**psubdev
)
230 if (!(*psubdev
= kzalloc(sizeof(**psubdev
), GFP_KERNEL
)))
232 nvkm_subdev_ctor(func
, device
, index
, *psubdev
);