| .. | .. |
|---|
| 21 | 21 | */ |
|---|
| 22 | 22 | #include "priv.h" |
|---|
| 23 | 23 | |
|---|
| 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> |
|---|
| 57 | 26 | |
|---|
| 58 | 27 | static void |
|---|
| 59 | 28 | nvkm_sec2_recv(struct work_struct *work) |
|---|
| 60 | 29 | { |
|---|
| 61 | 30 | struct nvkm_sec2 *sec2 = container_of(work, typeof(*sec2), work); |
|---|
| 62 | 31 | |
|---|
| 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; |
|---|
| 67 | 41 | } |
|---|
| 68 | 42 | |
|---|
| 69 | | - nvkm_msgqueue_recv(sec2->queue); |
|---|
| 43 | + nvkm_falcon_msgq_recv(sec2->msgq); |
|---|
| 70 | 44 | } |
|---|
| 71 | 45 | |
|---|
| 72 | | - |
|---|
| 73 | | -static int |
|---|
| 74 | | -nvkm_sec2_oneinit(struct nvkm_engine *engine) |
|---|
| 46 | +static void |
|---|
| 47 | +nvkm_sec2_intr(struct nvkm_engine *engine) |
|---|
| 75 | 48 | { |
|---|
| 76 | 49 | 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); |
|---|
| 79 | 51 | } |
|---|
| 80 | 52 | |
|---|
| 81 | 53 | static int |
|---|
| 82 | 54 | nvkm_sec2_fini(struct nvkm_engine *engine, bool suspend) |
|---|
| 83 | 55 | { |
|---|
| 84 | 56 | struct nvkm_sec2 *sec2 = nvkm_sec2(engine); |
|---|
| 57 | + |
|---|
| 85 | 58 | flush_work(&sec2->work); |
|---|
| 59 | + |
|---|
| 60 | + if (suspend) { |
|---|
| 61 | + nvkm_falcon_cmdq_fini(sec2->cmdq); |
|---|
| 62 | + sec2->initmsg_received = false; |
|---|
| 63 | + } |
|---|
| 64 | + |
|---|
| 86 | 65 | 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; |
|---|
| 87 | 77 | } |
|---|
| 88 | 78 | |
|---|
| 89 | 79 | static const struct nvkm_engine_func |
|---|
| 90 | 80 | nvkm_sec2 = { |
|---|
| 91 | 81 | .dtor = nvkm_sec2_dtor, |
|---|
| 92 | | - .oneinit = nvkm_sec2_oneinit, |
|---|
| 93 | 82 | .fini = nvkm_sec2_fini, |
|---|
| 94 | 83 | .intr = nvkm_sec2_intr, |
|---|
| 95 | 84 | }; |
|---|
| 96 | 85 | |
|---|
| 97 | 86 | 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) |
|---|
| 100 | 89 | { |
|---|
| 101 | 90 | struct nvkm_sec2 *sec2; |
|---|
| 91 | + int ret; |
|---|
| 102 | 92 | |
|---|
| 103 | 93 | if (!(sec2 = *psec2 = kzalloc(sizeof(*sec2), GFP_KERNEL))) |
|---|
| 104 | 94 | return -ENOMEM; |
|---|
| 105 | | - INIT_WORK(&sec2->work, nvkm_sec2_recv); |
|---|
| 106 | 95 | |
|---|
| 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; |
|---|
| 108 | 118 | }; |
|---|