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.
26 #include <core/client.h>
27 #include <core/gpuobj.h>
28 #include <subdev/fb.h>
29 #include <subdev/instmem.h>
31 #include <nvif/cl0002.h>
32 #include <nvif/unpack.h>
34 static const struct nvkm_object_func nvkm_dmaobj_func;
36 nvkm_dmaobj_search(struct nvkm_client *client, u64 handle)
38 struct nvkm_object *object;
40 object = nvkm_object_search(client, handle, &nvkm_dmaobj_func);
42 return (void *)object;
44 return nvkm_dmaobj(object);
48 nvkm_dmaobj_bind(struct nvkm_object *base, struct nvkm_gpuobj *gpuobj,
49 int align, struct nvkm_gpuobj **pgpuobj)
51 struct nvkm_dmaobj *dmaobj = nvkm_dmaobj(base);
52 return dmaobj->func->bind(dmaobj, gpuobj, align, pgpuobj);
56 nvkm_dmaobj_dtor(struct nvkm_object *base)
58 return nvkm_dmaobj(base);
61 static const struct nvkm_object_func
63 .dtor = nvkm_dmaobj_dtor,
64 .bind = nvkm_dmaobj_bind,
68 nvkm_dmaobj_ctor(const struct nvkm_dmaobj_func *func, struct nvkm_dma *dma,
69 const struct nvkm_oclass *oclass, void **pdata, u32 *psize,
70 struct nvkm_dmaobj *dmaobj)
75 struct nvkm_device *device = dma->engine.subdev.device;
76 struct nvkm_client *client = oclass->client;
77 struct nvkm_object *parent = oclass->parent;
78 struct nvkm_instmem *instmem = device->imem;
79 struct nvkm_fb *fb = device->fb;
84 nvkm_object_ctor(&nvkm_dmaobj_func, oclass, &dmaobj->object);
88 nvif_ioctl(parent, "create dma size %d\n", *psize);
89 if (!(ret = nvif_unpack(ret, &data, &size, args->v0, 0, 0, true))) {
90 nvif_ioctl(parent, "create dma vers %d target %d access %d "
91 "start %016llx limit %016llx\n",
92 args->v0.version, args->v0.target, args->v0.access,
93 args->v0.start, args->v0.limit);
94 dmaobj->target = args->v0.target;
95 dmaobj->access = args->v0.access;
96 dmaobj->start = args->v0.start;
97 dmaobj->limit = args->v0.limit;
104 if (dmaobj->start > dmaobj->limit)
107 switch (dmaobj->target) {
108 case NV_DMA_V0_TARGET_VM:
109 dmaobj->target = NV_MEM_TARGET_VM;
111 case NV_DMA_V0_TARGET_VRAM:
112 if (!client->super) {
113 if (dmaobj->limit >= fb->ram->size - instmem->reserved)
115 if (device->card_type >= NV_50)
118 dmaobj->target = NV_MEM_TARGET_VRAM;
120 case NV_DMA_V0_TARGET_PCI:
123 dmaobj->target = NV_MEM_TARGET_PCI;
125 case NV_DMA_V0_TARGET_PCI_US:
126 case NV_DMA_V0_TARGET_AGP:
129 dmaobj->target = NV_MEM_TARGET_PCI_NOSNOOP;
135 switch (dmaobj->access) {
136 case NV_DMA_V0_ACCESS_VM:
137 dmaobj->access = NV_MEM_ACCESS_VM;
139 case NV_DMA_V0_ACCESS_RD:
140 dmaobj->access = NV_MEM_ACCESS_RO;
142 case NV_DMA_V0_ACCESS_WR:
143 dmaobj->access = NV_MEM_ACCESS_WO;
145 case NV_DMA_V0_ACCESS_RDWR:
146 dmaobj->access = NV_MEM_ACCESS_RW;