blob: b04d4572603cce1ea231dffb46aeba9114ed1fa4 [file] [log] [blame]
Ben Skeggsebb945a2012-07-20 08:17:34 +10001/*
2 * Copyright 2012 Red Hat Inc.
3 *
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:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
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.
21 *
22 * Authors: Ben Skeggs
23 */
24
25#include <core/object.h>
26#include <core/class.h>
27
28#include <subdev/fb.h>
Ben Skeggsbc985402014-08-10 04:10:24 +100029
30#include "priv.h"
Ben Skeggsebb945a2012-07-20 08:17:34 +100031
Ben Skeggsf86770a2012-08-29 10:54:49 +100032static int
33nouveau_dmaobj_ctor(struct nouveau_object *parent,
34 struct nouveau_object *engine,
35 struct nouveau_oclass *oclass, void *data, u32 size,
36 struct nouveau_object **pobject)
Ben Skeggsebb945a2012-07-20 08:17:34 +100037{
Ben Skeggsf86770a2012-08-29 10:54:49 +100038 struct nouveau_dmaeng *dmaeng = (void *)engine;
39 struct nouveau_dmaobj *dmaobj;
40 struct nouveau_gpuobj *gpuobj;
Ben Skeggsebb945a2012-07-20 08:17:34 +100041 struct nv_dma_class *args = data;
Ben Skeggsebb945a2012-07-20 08:17:34 +100042 int ret;
43
44 if (size < sizeof(*args))
45 return -EINVAL;
46
Ben Skeggsf86770a2012-08-29 10:54:49 +100047 ret = nouveau_object_create(parent, engine, oclass, 0, &dmaobj);
48 *pobject = nv_object(dmaobj);
Ben Skeggsebb945a2012-07-20 08:17:34 +100049 if (ret)
50 return ret;
51
52 switch (args->flags & NV_DMA_TARGET_MASK) {
53 case NV_DMA_TARGET_VM:
Ben Skeggsf86770a2012-08-29 10:54:49 +100054 dmaobj->target = NV_MEM_TARGET_VM;
Ben Skeggsebb945a2012-07-20 08:17:34 +100055 break;
56 case NV_DMA_TARGET_VRAM:
Ben Skeggsf86770a2012-08-29 10:54:49 +100057 dmaobj->target = NV_MEM_TARGET_VRAM;
Ben Skeggsebb945a2012-07-20 08:17:34 +100058 break;
59 case NV_DMA_TARGET_PCI:
Ben Skeggsf86770a2012-08-29 10:54:49 +100060 dmaobj->target = NV_MEM_TARGET_PCI;
Ben Skeggsebb945a2012-07-20 08:17:34 +100061 break;
62 case NV_DMA_TARGET_PCI_US:
63 case NV_DMA_TARGET_AGP:
Ben Skeggsf86770a2012-08-29 10:54:49 +100064 dmaobj->target = NV_MEM_TARGET_PCI_NOSNOOP;
Ben Skeggsebb945a2012-07-20 08:17:34 +100065 break;
66 default:
67 return -EINVAL;
68 }
69
70 switch (args->flags & NV_DMA_ACCESS_MASK) {
71 case NV_DMA_ACCESS_VM:
Ben Skeggsf86770a2012-08-29 10:54:49 +100072 dmaobj->access = NV_MEM_ACCESS_VM;
Ben Skeggsebb945a2012-07-20 08:17:34 +100073 break;
74 case NV_DMA_ACCESS_RD:
Ben Skeggsf86770a2012-08-29 10:54:49 +100075 dmaobj->access = NV_MEM_ACCESS_RO;
Ben Skeggsebb945a2012-07-20 08:17:34 +100076 break;
77 case NV_DMA_ACCESS_WR:
Ben Skeggsf86770a2012-08-29 10:54:49 +100078 dmaobj->access = NV_MEM_ACCESS_WO;
Ben Skeggsebb945a2012-07-20 08:17:34 +100079 break;
80 case NV_DMA_ACCESS_RDWR:
Ben Skeggsf86770a2012-08-29 10:54:49 +100081 dmaobj->access = NV_MEM_ACCESS_RW;
Ben Skeggsebb945a2012-07-20 08:17:34 +100082 break;
83 default:
84 return -EINVAL;
85 }
86
Ben Skeggsf86770a2012-08-29 10:54:49 +100087 dmaobj->start = args->start;
88 dmaobj->limit = args->limit;
Ben Skeggsf7569442012-10-08 14:29:16 +100089 dmaobj->conf0 = args->conf0;
Ben Skeggsf86770a2012-08-29 10:54:49 +100090
91 switch (nv_mclass(parent)) {
Ben Skeggs586491e2014-08-10 04:10:24 +100092 case NV_DEVICE:
Ben Skeggs6c1689a2012-10-08 12:58:23 +100093 /* delayed, or no, binding */
Ben Skeggsf86770a2012-08-29 10:54:49 +100094 break;
95 default:
Ben Skeggs6c1689a2012-10-08 12:58:23 +100096 ret = dmaeng->bind(dmaeng, *pobject, dmaobj, &gpuobj);
97 if (ret == 0) {
98 nouveau_object_ref(NULL, pobject);
99 *pobject = nv_object(gpuobj);
100 }
101 break;
Ben Skeggsf86770a2012-08-29 10:54:49 +1000102 }
103
104 return ret;
Ben Skeggsebb945a2012-07-20 08:17:34 +1000105}
Ben Skeggsf86770a2012-08-29 10:54:49 +1000106
107static struct nouveau_ofuncs
108nouveau_dmaobj_ofuncs = {
109 .ctor = nouveau_dmaobj_ctor,
110 .dtor = nouveau_object_destroy,
111 .init = nouveau_object_init,
112 .fini = nouveau_object_fini,
113};
114
Ben Skeggsbc985402014-08-10 04:10:24 +1000115static struct nouveau_oclass
Ben Skeggsf86770a2012-08-29 10:54:49 +1000116nouveau_dmaobj_sclass[] = {
117 { NV_DMA_FROM_MEMORY_CLASS, &nouveau_dmaobj_ofuncs },
118 { NV_DMA_TO_MEMORY_CLASS, &nouveau_dmaobj_ofuncs },
119 { NV_DMA_IN_MEMORY_CLASS, &nouveau_dmaobj_ofuncs },
120 {}
121};
Ben Skeggsbc985402014-08-10 04:10:24 +1000122
123int
124_nvkm_dmaeng_ctor(struct nouveau_object *parent, struct nouveau_object *engine,
125 struct nouveau_oclass *oclass, void *data, u32 size,
126 struct nouveau_object **pobject)
127{
128 const struct nvkm_dmaeng_impl *impl = (void *)oclass;
129 struct nouveau_dmaeng *dmaeng;
130 int ret;
131
132 ret = nouveau_engine_create(parent, engine, oclass, true, "DMAOBJ",
133 "dmaobj", &dmaeng);
134 *pobject = nv_object(dmaeng);
135 if (ret)
136 return ret;
137
138 nv_engine(dmaeng)->sclass = nouveau_dmaobj_sclass;
139 dmaeng->bind = impl->bind;
140 return 0;
141}