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.
24 #define gf100_dmaobj(p) container_of((p), struct gf100_dmaobj, base)
27 #include <core/client.h>
28 #include <core/gpuobj.h>
29 #include <subdev/fb.h>
31 #include <nvif/cl0002.h>
32 #include <nvif/unpack.h>
35 struct nvkm_dmaobj base;
41 gf100_dmaobj_bind(struct nvkm_dmaobj *base, struct nvkm_gpuobj *parent,
42 int align, struct nvkm_gpuobj **pgpuobj)
44 struct gf100_dmaobj *dmaobj = gf100_dmaobj(base);
45 struct nvkm_device *device = dmaobj->base.dma->engine.subdev.device;
48 ret = nvkm_gpuobj_new(device, 24, align, false, parent, pgpuobj);
51 nvkm_wo32(*pgpuobj, 0x00, dmaobj->flags0);
52 nvkm_wo32(*pgpuobj, 0x04, lower_32_bits(dmaobj->base.limit));
53 nvkm_wo32(*pgpuobj, 0x08, lower_32_bits(dmaobj->base.start));
54 nvkm_wo32(*pgpuobj, 0x0c, upper_32_bits(dmaobj->base.limit) << 24 |
55 upper_32_bits(dmaobj->base.start));
56 nvkm_wo32(*pgpuobj, 0x10, 0x00000000);
57 nvkm_wo32(*pgpuobj, 0x14, dmaobj->flags5);
64 static const struct nvkm_dmaobj_func
66 .bind = gf100_dmaobj_bind,
70 gf100_dmaobj_new(struct nvkm_dma *dma, const struct nvkm_oclass *oclass,
71 void *data, u32 size, struct nvkm_dmaobj **pdmaobj)
74 struct gf100_dma_v0 v0;
76 struct nvkm_object *parent = oclass->parent;
77 struct gf100_dmaobj *dmaobj;
81 if (!(dmaobj = kzalloc(sizeof(*dmaobj), GFP_KERNEL)))
83 *pdmaobj = &dmaobj->base;
85 ret = nvkm_dmaobj_ctor(&gf100_dmaobj_func, dma, oclass,
86 &data, &size, &dmaobj->base);
93 nvif_ioctl(parent, "create gf100 dma size %d\n", size);
94 if (!(ret = nvif_unpack(ret, &data, &size, args->v0, 0, 0, false))) {
96 "create gf100 dma vers %d priv %d kind %02x\n",
97 args->v0.version, args->v0.priv, args->v0.kind);
103 if (dmaobj->base.target != NV_MEM_TARGET_VM) {
104 kind = GF100_DMA_V0_KIND_PITCH;
105 user = GF100_DMA_V0_PRIV_US;
108 kind = GF100_DMA_V0_KIND_VM;
109 user = GF100_DMA_V0_PRIV_VM;
117 dmaobj->flags0 |= (kind << 22) | (user << 20) | oclass->base.oclass;
118 dmaobj->flags5 |= (unkn << 16);
120 switch (dmaobj->base.target) {
121 case NV_MEM_TARGET_VM:
122 dmaobj->flags0 |= 0x00000000;
124 case NV_MEM_TARGET_VRAM:
125 dmaobj->flags0 |= 0x00010000;
127 case NV_MEM_TARGET_PCI:
128 dmaobj->flags0 |= 0x00020000;
130 case NV_MEM_TARGET_PCI_NOSNOOP:
131 dmaobj->flags0 |= 0x00030000;
137 switch (dmaobj->base.access) {
138 case NV_MEM_ACCESS_VM:
140 case NV_MEM_ACCESS_RO:
141 dmaobj->flags0 |= 0x00040000;
143 case NV_MEM_ACCESS_WO:
144 case NV_MEM_ACCESS_RW:
145 dmaobj->flags0 |= 0x00080000;