Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
[cris-mirror.git] / drivers / gpu / drm / nouveau / nvkm / engine / dma / base.c
blob11b7b8fd5ddaf356b5a9bee8dbde507c70cf92ac
1 /*
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.
22 * Authors: Ben Skeggs
24 #include "priv.h"
26 #include <core/client.h>
27 #include <engine/fifo.h>
29 #include <nvif/class.h>
31 static int
32 nvkm_dma_oclass_new(struct nvkm_device *device,
33 const struct nvkm_oclass *oclass, void *data, u32 size,
34 struct nvkm_object **pobject)
36 struct nvkm_dma *dma = nvkm_dma(oclass->engine);
37 struct nvkm_dmaobj *dmaobj = NULL;
38 int ret;
40 ret = dma->func->class_new(dma, oclass, data, size, &dmaobj);
41 if (dmaobj)
42 *pobject = &dmaobj->object;
43 return ret;
46 static const struct nvkm_device_oclass
47 nvkm_dma_oclass_base = {
48 .ctor = nvkm_dma_oclass_new,
51 static int
52 nvkm_dma_oclass_fifo_new(const struct nvkm_oclass *oclass, void *data, u32 size,
53 struct nvkm_object **pobject)
55 return nvkm_dma_oclass_new(oclass->engine->subdev.device,
56 oclass, data, size, pobject);
59 static const struct nvkm_sclass
60 nvkm_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 },
66 static int
67 nvkm_dma_oclass_base_get(struct nvkm_oclass *sclass, int index,
68 const struct nvkm_device_oclass **class)
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;
78 return count;
81 static int
82 nvkm_dma_oclass_fifo_get(struct nvkm_oclass *oclass, int index)
84 const int count = ARRAY_SIZE(nvkm_dma_sclass);
85 if (index < count) {
86 oclass->base = nvkm_dma_sclass[index];
87 return index;
89 return count;
92 static void *
93 nvkm_dma_dtor(struct nvkm_engine *engine)
95 return nvkm_dma(engine);
98 static const struct nvkm_engine_func
99 nvkm_dma = {
100 .dtor = nvkm_dma_dtor,
101 .base.sclass = nvkm_dma_oclass_base_get,
102 .fifo.sclass = nvkm_dma_oclass_fifo_get,
106 nvkm_dma_new_(const struct nvkm_dma_func *func, struct nvkm_device *device,
107 int index, struct nvkm_dma **pdma)
109 struct nvkm_dma *dma;
111 if (!(dma = *pdma = kzalloc(sizeof(*dma), GFP_KERNEL)))
112 return -ENOMEM;
113 dma->func = func;
115 return nvkm_engine_ctor(&nvkm_dma, device, index, true, &dma->engine);