1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24#include "priv.h"
25
26#include <core/client.h>
27#include <engine/fifo.h>
28
29#include <nvif/class.h>
30
31static int
32nvkm_dma_oclass_new(struct nvkm_device *device,
33 const struct nvkm_oclass *oclass, void *data, u32 size,
34 struct nvkm_object **pobject)
35{
36 struct nvkm_dma *dma = nvkm_dma(oclass->engine);
37 struct nvkm_dmaobj *dmaobj = NULL;
38 int ret;
39
40 ret = dma->func->class_new(dma, oclass, data, size, &dmaobj);
41 if (dmaobj)
42 *pobject = &dmaobj->object;
43 return ret;
44}
45
46static const struct nvkm_device_oclass
47nvkm_dma_oclass_base = {
48 .ctor = nvkm_dma_oclass_new,
49};
50
51static int
52nvkm_dma_oclass_fifo_new(const struct nvkm_oclass *oclass, void *data, u32 size,
53 struct nvkm_object **pobject)
54{
55 return nvkm_dma_oclass_new(oclass->engine->subdev.device,
56 oclass, data, size, pobject);
57}
58
59static const struct nvkm_sclass
60nvkm_dma_sclass[] = {
61 { 0, 0, NV_DMA_FROM_MEMORY, NULL, nvkm_dma_oclass_fifo_new },
62 { 0, 0, NV_DMA_TO_MEMORY, NULL, nvkm_dma_oclass_fifo_new },
63 { 0, 0, NV_DMA_IN_MEMORY, NULL, nvkm_dma_oclass_fifo_new },
64};
65
66static int
67nvkm_dma_oclass_base_get(struct nvkm_oclass *sclass, int index,
68 const struct nvkm_device_oclass **class)
69{
70 const int count = ARRAY_SIZE(nvkm_dma_sclass);
71 if (index < count) {
72 const struct nvkm_sclass *oclass = &nvkm_dma_sclass[index];
73 sclass->base = oclass[0];
74 sclass->engn = oclass;
75 *class = &nvkm_dma_oclass_base;
76 return index;
77 }
78 return count;
79}
80
81static int
82nvkm_dma_oclass_fifo_get(struct nvkm_oclass *oclass, int index)
83{
84 const int count = ARRAY_SIZE(nvkm_dma_sclass);
85 if (index < count) {
86 oclass->base = nvkm_dma_sclass[index];
87 return index;
88 }
89 return count;
90}
91
92static void *
93nvkm_dma_dtor(struct nvkm_engine *engine)
94{
95 return nvkm_dma(engine);
96}
97
98static const struct nvkm_engine_func
99nvkm_dma = {
100 .dtor = nvkm_dma_dtor,
101 .base.sclass = nvkm_dma_oclass_base_get,
102 .fifo.sclass = nvkm_dma_oclass_fifo_get,
103};
104
105int
106nvkm_dma_new_(const struct nvkm_dma_func *func, struct nvkm_device *device,
107 enum nvkm_subdev_type type, int inst, struct nvkm_dma **pdma)
108{
109 struct nvkm_dma *dma;
110
111 if (!(dma = *pdma = kzalloc(sizeof(*dma), GFP_KERNEL)))
112 return -ENOMEM;
113 dma->func = func;
114
115 return nvkm_engine_ctor(&nvkm_dma, device, type, inst, true, &dma->engine);
116}
117