0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024 #include <core/subdev.h>
0025 #include <core/device.h>
0026 #include <core/option.h>
0027 #include <subdev/mc.h>
0028
0029 const char *
0030 nvkm_subdev_type[NVKM_SUBDEV_NR] = {
0031 #define NVKM_LAYOUT_ONCE(type,data,ptr,...) [type] = #ptr,
0032 #define NVKM_LAYOUT_INST(A...) NVKM_LAYOUT_ONCE(A)
0033 #include <core/layout.h>
0034 #undef NVKM_LAYOUT_ONCE
0035 #undef NVKM_LAYOUT_INST
0036 };
0037
0038 void
0039 nvkm_subdev_intr(struct nvkm_subdev *subdev)
0040 {
0041 if (subdev->func->intr)
0042 subdev->func->intr(subdev);
0043 }
0044
0045 int
0046 nvkm_subdev_info(struct nvkm_subdev *subdev, u64 mthd, u64 *data)
0047 {
0048 if (subdev->func->info)
0049 return subdev->func->info(subdev, mthd, data);
0050 return -ENOSYS;
0051 }
0052
0053 int
0054 nvkm_subdev_fini(struct nvkm_subdev *subdev, bool suspend)
0055 {
0056 struct nvkm_device *device = subdev->device;
0057 const char *action = suspend ? "suspend" : "fini";
0058 s64 time;
0059
0060 nvkm_trace(subdev, "%s running...\n", action);
0061 time = ktime_to_us(ktime_get());
0062
0063 if (subdev->func->fini) {
0064 int ret = subdev->func->fini(subdev, suspend);
0065 if (ret) {
0066 nvkm_error(subdev, "%s failed, %d\n", action, ret);
0067 if (suspend)
0068 return ret;
0069 }
0070 }
0071
0072 nvkm_mc_reset(device, subdev->type, subdev->inst);
0073
0074 time = ktime_to_us(ktime_get()) - time;
0075 nvkm_trace(subdev, "%s completed in %lldus\n", action, time);
0076 return 0;
0077 }
0078
0079 int
0080 nvkm_subdev_preinit(struct nvkm_subdev *subdev)
0081 {
0082 s64 time;
0083
0084 nvkm_trace(subdev, "preinit running...\n");
0085 time = ktime_to_us(ktime_get());
0086
0087 if (subdev->func->preinit) {
0088 int ret = subdev->func->preinit(subdev);
0089 if (ret) {
0090 nvkm_error(subdev, "preinit failed, %d\n", ret);
0091 return ret;
0092 }
0093 }
0094
0095 time = ktime_to_us(ktime_get()) - time;
0096 nvkm_trace(subdev, "preinit completed in %lldus\n", time);
0097 return 0;
0098 }
0099
0100 int
0101 nvkm_subdev_init(struct nvkm_subdev *subdev)
0102 {
0103 s64 time;
0104 int ret;
0105
0106 nvkm_trace(subdev, "init running...\n");
0107 time = ktime_to_us(ktime_get());
0108
0109 if (subdev->func->oneinit && !subdev->oneinit) {
0110 s64 time;
0111 nvkm_trace(subdev, "one-time init running...\n");
0112 time = ktime_to_us(ktime_get());
0113 ret = subdev->func->oneinit(subdev);
0114 if (ret) {
0115 nvkm_error(subdev, "one-time init failed, %d\n", ret);
0116 return ret;
0117 }
0118
0119 subdev->oneinit = true;
0120 time = ktime_to_us(ktime_get()) - time;
0121 nvkm_trace(subdev, "one-time init completed in %lldus\n", time);
0122 }
0123
0124 if (subdev->func->init) {
0125 ret = subdev->func->init(subdev);
0126 if (ret) {
0127 nvkm_error(subdev, "init failed, %d\n", ret);
0128 return ret;
0129 }
0130 }
0131
0132 time = ktime_to_us(ktime_get()) - time;
0133 nvkm_trace(subdev, "init completed in %lldus\n", time);
0134 return 0;
0135 }
0136
0137 void
0138 nvkm_subdev_del(struct nvkm_subdev **psubdev)
0139 {
0140 struct nvkm_subdev *subdev = *psubdev;
0141 s64 time;
0142
0143 if (subdev && !WARN_ON(!subdev->func)) {
0144 nvkm_trace(subdev, "destroy running...\n");
0145 time = ktime_to_us(ktime_get());
0146 list_del(&subdev->head);
0147 if (subdev->func->dtor)
0148 *psubdev = subdev->func->dtor(subdev);
0149 time = ktime_to_us(ktime_get()) - time;
0150 nvkm_trace(subdev, "destroy completed in %lldus\n", time);
0151 kfree(*psubdev);
0152 *psubdev = NULL;
0153 }
0154 }
0155
0156 void
0157 nvkm_subdev_disable(struct nvkm_device *device, enum nvkm_subdev_type type, int inst)
0158 {
0159 struct nvkm_subdev *subdev;
0160 list_for_each_entry(subdev, &device->subdev, head) {
0161 if (subdev->type == type && subdev->inst == inst) {
0162 *subdev->pself = NULL;
0163 nvkm_subdev_del(&subdev);
0164 break;
0165 }
0166 }
0167 }
0168
0169 void
0170 nvkm_subdev_ctor(const struct nvkm_subdev_func *func, struct nvkm_device *device,
0171 enum nvkm_subdev_type type, int inst, struct nvkm_subdev *subdev)
0172 {
0173 subdev->func = func;
0174 subdev->device = device;
0175 subdev->type = type;
0176 subdev->inst = inst < 0 ? 0 : inst;
0177
0178 if (inst >= 0)
0179 snprintf(subdev->name, sizeof(subdev->name), "%s%d", nvkm_subdev_type[type], inst);
0180 else
0181 strscpy(subdev->name, nvkm_subdev_type[type], sizeof(subdev->name));
0182 subdev->debug = nvkm_dbgopt(device->dbgopt, subdev->name);
0183 list_add_tail(&subdev->head, &device->subdev);
0184 }
0185
0186 int
0187 nvkm_subdev_new_(const struct nvkm_subdev_func *func, struct nvkm_device *device,
0188 enum nvkm_subdev_type type, int inst, struct nvkm_subdev **psubdev)
0189 {
0190 if (!(*psubdev = kzalloc(sizeof(**psubdev), GFP_KERNEL)))
0191 return -ENOMEM;
0192 nvkm_subdev_ctor(func, device, type, inst, *psubdev);
0193 return 0;
0194 }