forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-04 1543e317f1da31b75942316931e8f491a8920811
kernel/drivers/gpu/drm/nouveau/nvkm/engine/sec2/base.c
....@@ -21,88 +21,98 @@
2121 */
2222 #include "priv.h"
2323
24
-#include <core/msgqueue.h>
25
-#include <engine/falcon.h>
26
-
27
-static void *
28
-nvkm_sec2_dtor(struct nvkm_engine *engine)
29
-{
30
- struct nvkm_sec2 *sec2 = nvkm_sec2(engine);
31
- nvkm_msgqueue_del(&sec2->queue);
32
- nvkm_falcon_del(&sec2->falcon);
33
- return sec2;
34
-}
35
-
36
-static void
37
-nvkm_sec2_intr(struct nvkm_engine *engine)
38
-{
39
- struct nvkm_sec2 *sec2 = nvkm_sec2(engine);
40
- struct nvkm_subdev *subdev = &engine->subdev;
41
- struct nvkm_device *device = subdev->device;
42
- u32 disp = nvkm_rd32(device, 0x8701c);
43
- u32 intr = nvkm_rd32(device, 0x87008) & disp & ~(disp >> 16);
44
-
45
- if (intr & 0x00000040) {
46
- schedule_work(&sec2->work);
47
- nvkm_wr32(device, 0x87004, 0x00000040);
48
- intr &= ~0x00000040;
49
- }
50
-
51
- if (intr) {
52
- nvkm_error(subdev, "unhandled intr %08x\n", intr);
53
- nvkm_wr32(device, 0x87004, intr);
54
-
55
- }
56
-}
24
+#include <core/firmware.h>
25
+#include <subdev/top.h>
5726
5827 static void
5928 nvkm_sec2_recv(struct work_struct *work)
6029 {
6130 struct nvkm_sec2 *sec2 = container_of(work, typeof(*sec2), work);
6231
63
- if (!sec2->queue) {
64
- nvkm_warn(&sec2->engine.subdev,
65
- "recv function called while no firmware set!\n");
66
- return;
32
+ if (!sec2->initmsg_received) {
33
+ int ret = sec2->func->initmsg(sec2);
34
+ if (ret) {
35
+ nvkm_error(&sec2->engine.subdev,
36
+ "error parsing init message: %d\n", ret);
37
+ return;
38
+ }
39
+
40
+ sec2->initmsg_received = true;
6741 }
6842
69
- nvkm_msgqueue_recv(sec2->queue);
43
+ nvkm_falcon_msgq_recv(sec2->msgq);
7044 }
7145
72
-
73
-static int
74
-nvkm_sec2_oneinit(struct nvkm_engine *engine)
46
+static void
47
+nvkm_sec2_intr(struct nvkm_engine *engine)
7548 {
7649 struct nvkm_sec2 *sec2 = nvkm_sec2(engine);
77
- return nvkm_falcon_v1_new(&sec2->engine.subdev, "SEC2", 0x87000,
78
- &sec2->falcon);
50
+ sec2->func->intr(sec2);
7951 }
8052
8153 static int
8254 nvkm_sec2_fini(struct nvkm_engine *engine, bool suspend)
8355 {
8456 struct nvkm_sec2 *sec2 = nvkm_sec2(engine);
57
+
8558 flush_work(&sec2->work);
59
+
60
+ if (suspend) {
61
+ nvkm_falcon_cmdq_fini(sec2->cmdq);
62
+ sec2->initmsg_received = false;
63
+ }
64
+
8665 return 0;
66
+}
67
+
68
+static void *
69
+nvkm_sec2_dtor(struct nvkm_engine *engine)
70
+{
71
+ struct nvkm_sec2 *sec2 = nvkm_sec2(engine);
72
+ nvkm_falcon_msgq_del(&sec2->msgq);
73
+ nvkm_falcon_cmdq_del(&sec2->cmdq);
74
+ nvkm_falcon_qmgr_del(&sec2->qmgr);
75
+ nvkm_falcon_dtor(&sec2->falcon);
76
+ return sec2;
8777 }
8878
8979 static const struct nvkm_engine_func
9080 nvkm_sec2 = {
9181 .dtor = nvkm_sec2_dtor,
92
- .oneinit = nvkm_sec2_oneinit,
9382 .fini = nvkm_sec2_fini,
9483 .intr = nvkm_sec2_intr,
9584 };
9685
9786 int
98
-nvkm_sec2_new_(struct nvkm_device *device, int index,
99
- struct nvkm_sec2 **psec2)
87
+nvkm_sec2_new_(const struct nvkm_sec2_fwif *fwif, struct nvkm_device *device,
88
+ int index, u32 addr, struct nvkm_sec2 **psec2)
10089 {
10190 struct nvkm_sec2 *sec2;
91
+ int ret;
10292
10393 if (!(sec2 = *psec2 = kzalloc(sizeof(*sec2), GFP_KERNEL)))
10494 return -ENOMEM;
105
- INIT_WORK(&sec2->work, nvkm_sec2_recv);
10695
107
- return nvkm_engine_ctor(&nvkm_sec2, device, index, true, &sec2->engine);
96
+ ret = nvkm_engine_ctor(&nvkm_sec2, device, index, true, &sec2->engine);
97
+ if (ret)
98
+ return ret;
99
+
100
+ fwif = nvkm_firmware_load(&sec2->engine.subdev, fwif, "Sec2", sec2);
101
+ if (IS_ERR(fwif))
102
+ return PTR_ERR(fwif);
103
+
104
+ sec2->func = fwif->func;
105
+
106
+ ret = nvkm_falcon_ctor(sec2->func->flcn, &sec2->engine.subdev,
107
+ nvkm_subdev_name[index], addr, &sec2->falcon);
108
+ if (ret)
109
+ return ret;
110
+
111
+ if ((ret = nvkm_falcon_qmgr_new(&sec2->falcon, &sec2->qmgr)) ||
112
+ (ret = nvkm_falcon_cmdq_new(sec2->qmgr, "cmdq", &sec2->cmdq)) ||
113
+ (ret = nvkm_falcon_msgq_new(sec2->qmgr, "msgq", &sec2->msgq)))
114
+ return ret;
115
+
116
+ INIT_WORK(&sec2->work, nvkm_sec2_recv);
117
+ return 0;
108118 };