1*6fb566b9SBen Skeggs /*
2*6fb566b9SBen Skeggs * Copyright 2018 Red Hat Inc.
3*6fb566b9SBen Skeggs *
4*6fb566b9SBen Skeggs * Permission is hereby granted, free of charge, to any person obtaining a
5*6fb566b9SBen Skeggs * copy of this software and associated documentation files (the "Software"),
6*6fb566b9SBen Skeggs * to deal in the Software without restriction, including without limitation
7*6fb566b9SBen Skeggs * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8*6fb566b9SBen Skeggs * and/or sell copies of the Software, and to permit persons to whom the
9*6fb566b9SBen Skeggs * Software is furnished to do so, subject to the following conditions:
10*6fb566b9SBen Skeggs *
11*6fb566b9SBen Skeggs * The above copyright notice and this permission notice shall be included in
12*6fb566b9SBen Skeggs * all copies or substantial portions of the Software.
13*6fb566b9SBen Skeggs *
14*6fb566b9SBen Skeggs * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15*6fb566b9SBen Skeggs * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16*6fb566b9SBen Skeggs * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17*6fb566b9SBen Skeggs * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18*6fb566b9SBen Skeggs * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19*6fb566b9SBen Skeggs * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20*6fb566b9SBen Skeggs * OTHER DEALINGS IN THE SOFTWARE.
21*6fb566b9SBen Skeggs */
22*6fb566b9SBen Skeggs #define gv100_dmaobj(p) container_of((p), struct gv100_dmaobj, base)
23*6fb566b9SBen Skeggs #include "user.h"
24*6fb566b9SBen Skeggs
25*6fb566b9SBen Skeggs #include <core/client.h>
26*6fb566b9SBen Skeggs #include <core/gpuobj.h>
27*6fb566b9SBen Skeggs #include <subdev/fb.h>
28*6fb566b9SBen Skeggs
29*6fb566b9SBen Skeggs #include <nvif/cl0002.h>
30*6fb566b9SBen Skeggs #include <nvif/unpack.h>
31*6fb566b9SBen Skeggs
32*6fb566b9SBen Skeggs struct gv100_dmaobj {
33*6fb566b9SBen Skeggs struct nvkm_dmaobj base;
34*6fb566b9SBen Skeggs u32 flags0;
35*6fb566b9SBen Skeggs };
36*6fb566b9SBen Skeggs
37*6fb566b9SBen Skeggs static int
gv100_dmaobj_bind(struct nvkm_dmaobj * base,struct nvkm_gpuobj * parent,int align,struct nvkm_gpuobj ** pgpuobj)38*6fb566b9SBen Skeggs gv100_dmaobj_bind(struct nvkm_dmaobj *base, struct nvkm_gpuobj *parent,
39*6fb566b9SBen Skeggs int align, struct nvkm_gpuobj **pgpuobj)
40*6fb566b9SBen Skeggs {
41*6fb566b9SBen Skeggs struct gv100_dmaobj *dmaobj = gv100_dmaobj(base);
42*6fb566b9SBen Skeggs struct nvkm_device *device = dmaobj->base.dma->engine.subdev.device;
43*6fb566b9SBen Skeggs u64 start = dmaobj->base.start >> 8;
44*6fb566b9SBen Skeggs u64 limit = dmaobj->base.limit >> 8;
45*6fb566b9SBen Skeggs int ret;
46*6fb566b9SBen Skeggs
47*6fb566b9SBen Skeggs ret = nvkm_gpuobj_new(device, 24, align, false, parent, pgpuobj);
48*6fb566b9SBen Skeggs if (ret == 0) {
49*6fb566b9SBen Skeggs nvkm_kmap(*pgpuobj);
50*6fb566b9SBen Skeggs nvkm_wo32(*pgpuobj, 0x00, dmaobj->flags0);
51*6fb566b9SBen Skeggs nvkm_wo32(*pgpuobj, 0x04, lower_32_bits(start));
52*6fb566b9SBen Skeggs nvkm_wo32(*pgpuobj, 0x08, upper_32_bits(start));
53*6fb566b9SBen Skeggs nvkm_wo32(*pgpuobj, 0x0c, lower_32_bits(limit));
54*6fb566b9SBen Skeggs nvkm_wo32(*pgpuobj, 0x10, upper_32_bits(limit));
55*6fb566b9SBen Skeggs nvkm_done(*pgpuobj);
56*6fb566b9SBen Skeggs }
57*6fb566b9SBen Skeggs
58*6fb566b9SBen Skeggs return ret;
59*6fb566b9SBen Skeggs }
60*6fb566b9SBen Skeggs
61*6fb566b9SBen Skeggs static const struct nvkm_dmaobj_func
62*6fb566b9SBen Skeggs gv100_dmaobj_func = {
63*6fb566b9SBen Skeggs .bind = gv100_dmaobj_bind,
64*6fb566b9SBen Skeggs };
65*6fb566b9SBen Skeggs
66*6fb566b9SBen Skeggs int
gv100_dmaobj_new(struct nvkm_dma * dma,const struct nvkm_oclass * oclass,void * data,u32 size,struct nvkm_dmaobj ** pdmaobj)67*6fb566b9SBen Skeggs gv100_dmaobj_new(struct nvkm_dma *dma, const struct nvkm_oclass *oclass,
68*6fb566b9SBen Skeggs void *data, u32 size, struct nvkm_dmaobj **pdmaobj)
69*6fb566b9SBen Skeggs {
70*6fb566b9SBen Skeggs union {
71*6fb566b9SBen Skeggs struct gf119_dma_v0 v0;
72*6fb566b9SBen Skeggs } *args;
73*6fb566b9SBen Skeggs struct nvkm_object *parent = oclass->parent;
74*6fb566b9SBen Skeggs struct gv100_dmaobj *dmaobj;
75*6fb566b9SBen Skeggs u32 kind, page;
76*6fb566b9SBen Skeggs int ret;
77*6fb566b9SBen Skeggs
78*6fb566b9SBen Skeggs if (!(dmaobj = kzalloc(sizeof(*dmaobj), GFP_KERNEL)))
79*6fb566b9SBen Skeggs return -ENOMEM;
80*6fb566b9SBen Skeggs *pdmaobj = &dmaobj->base;
81*6fb566b9SBen Skeggs
82*6fb566b9SBen Skeggs ret = nvkm_dmaobj_ctor(&gv100_dmaobj_func, dma, oclass,
83*6fb566b9SBen Skeggs &data, &size, &dmaobj->base);
84*6fb566b9SBen Skeggs if (ret)
85*6fb566b9SBen Skeggs return ret;
86*6fb566b9SBen Skeggs
87*6fb566b9SBen Skeggs ret = -ENOSYS;
88*6fb566b9SBen Skeggs args = data;
89*6fb566b9SBen Skeggs
90*6fb566b9SBen Skeggs nvif_ioctl(parent, "create gv100 dma size %d\n", size);
91*6fb566b9SBen Skeggs if (!(ret = nvif_unpack(ret, &data, &size, args->v0, 0, 0, false))) {
92*6fb566b9SBen Skeggs nvif_ioctl(parent,
93*6fb566b9SBen Skeggs "create gv100 dma vers %d page %d kind %02x\n",
94*6fb566b9SBen Skeggs args->v0.version, args->v0.page, args->v0.kind);
95*6fb566b9SBen Skeggs kind = args->v0.kind != 0;
96*6fb566b9SBen Skeggs page = args->v0.page != 0;
97*6fb566b9SBen Skeggs } else
98*6fb566b9SBen Skeggs if (size == 0) {
99*6fb566b9SBen Skeggs kind = 0;
100*6fb566b9SBen Skeggs page = GF119_DMA_V0_PAGE_SP;
101*6fb566b9SBen Skeggs } else
102*6fb566b9SBen Skeggs return ret;
103*6fb566b9SBen Skeggs
104*6fb566b9SBen Skeggs if (kind)
105*6fb566b9SBen Skeggs dmaobj->flags0 |= 0x00100000;
106*6fb566b9SBen Skeggs if (page)
107*6fb566b9SBen Skeggs dmaobj->flags0 |= 0x00000040;
108*6fb566b9SBen Skeggs dmaobj->flags0 |= 0x00000004; /* rw */
109*6fb566b9SBen Skeggs
110*6fb566b9SBen Skeggs switch (dmaobj->base.target) {
111*6fb566b9SBen Skeggs case NV_MEM_TARGET_VRAM : dmaobj->flags0 |= 0x00000001; break;
112*6fb566b9SBen Skeggs case NV_MEM_TARGET_PCI : dmaobj->flags0 |= 0x00000002; break;
113*6fb566b9SBen Skeggs case NV_MEM_TARGET_PCI_NOSNOOP: dmaobj->flags0 |= 0x00000003; break;
114*6fb566b9SBen Skeggs default:
115*6fb566b9SBen Skeggs return -EINVAL;
116*6fb566b9SBen Skeggs }
117*6fb566b9SBen Skeggs
118*6fb566b9SBen Skeggs return 0;
119*6fb566b9SBen Skeggs }
120