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.
25 #include <core/client.h>
26 #include <core/gpuobj.h>
27 #include <core/class.h>
28 #include <nvif/unpack.h>
29 #include <nvif/class.h>
31 #include <subdev/fb.h>
35 struct nv50_dmaobj_priv
{
36 struct nouveau_dmaobj base
;
42 nv50_dmaobj_bind(struct nouveau_dmaobj
*dmaobj
,
43 struct nouveau_object
*parent
,
44 struct nouveau_gpuobj
**pgpuobj
)
46 struct nv50_dmaobj_priv
*priv
= (void *)dmaobj
;
49 if (!nv_iclass(parent
, NV_ENGCTX_CLASS
)) {
50 switch (nv_mclass(parent
->parent
)) {
51 case NV40_CHANNEL_DMA
:
52 case NV50_CHANNEL_GPFIFO
:
53 case G82_CHANNEL_GPFIFO
:
54 case NV50_DISP_MAST_CLASS
:
55 case NV84_DISP_MAST_CLASS
:
56 case NV94_DISP_MAST_CLASS
:
57 case NVA0_DISP_MAST_CLASS
:
58 case NVA3_DISP_MAST_CLASS
:
59 case NV50_DISP_SYNC_CLASS
:
60 case NV84_DISP_SYNC_CLASS
:
61 case NV94_DISP_SYNC_CLASS
:
62 case NVA0_DISP_SYNC_CLASS
:
63 case NVA3_DISP_SYNC_CLASS
:
64 case NV50_DISP_OVLY_CLASS
:
65 case NV84_DISP_OVLY_CLASS
:
66 case NV94_DISP_OVLY_CLASS
:
67 case NVA0_DISP_OVLY_CLASS
:
68 case NVA3_DISP_OVLY_CLASS
:
75 ret
= nouveau_gpuobj_new(parent
, parent
, 24, 32, 0, pgpuobj
);
77 nv_wo32(*pgpuobj
, 0x00, priv
->flags0
| nv_mclass(dmaobj
));
78 nv_wo32(*pgpuobj
, 0x04, lower_32_bits(priv
->base
.limit
));
79 nv_wo32(*pgpuobj
, 0x08, lower_32_bits(priv
->base
.start
));
80 nv_wo32(*pgpuobj
, 0x0c, upper_32_bits(priv
->base
.limit
) << 24 |
81 upper_32_bits(priv
->base
.start
));
82 nv_wo32(*pgpuobj
, 0x10, 0x00000000);
83 nv_wo32(*pgpuobj
, 0x14, priv
->flags5
);
90 nv50_dmaobj_ctor(struct nouveau_object
*parent
, struct nouveau_object
*engine
,
91 struct nouveau_oclass
*oclass
, void *data
, u32 size
,
92 struct nouveau_object
**pobject
)
94 struct nouveau_dmaeng
*dmaeng
= (void *)engine
;
96 struct nv50_dma_v0 v0
;
98 struct nv50_dmaobj_priv
*priv
;
99 u32 user
, part
, comp
, kind
;
102 ret
= nvkm_dmaobj_create(parent
, engine
, oclass
, &data
, &size
, &priv
);
103 *pobject
= nv_object(priv
);
108 nv_ioctl(parent
, "create nv50 dma size %d\n", size
);
109 if (nvif_unpack(args
->v0
, 0, 0, false)) {
110 nv_ioctl(parent
, "create nv50 dma vers %d priv %d part %d "
111 "comp %d kind %02x\n", args
->v0
.version
,
112 args
->v0
.priv
, args
->v0
.part
, args
->v0
.comp
,
114 user
= args
->v0
.priv
;
115 part
= args
->v0
.part
;
116 comp
= args
->v0
.comp
;
117 kind
= args
->v0
.kind
;
120 if (priv
->base
.target
!= NV_MEM_TARGET_VM
) {
121 user
= NV50_DMA_V0_PRIV_US
;
122 part
= NV50_DMA_V0_PART_256
;
123 comp
= NV50_DMA_V0_COMP_NONE
;
124 kind
= NV50_DMA_V0_KIND_PITCH
;
126 user
= NV50_DMA_V0_PRIV_VM
;
127 part
= NV50_DMA_V0_PART_VM
;
128 comp
= NV50_DMA_V0_COMP_VM
;
129 kind
= NV50_DMA_V0_KIND_VM
;
134 if (user
> 2 || part
> 2 || comp
> 3 || kind
> 0x7f)
136 priv
->flags0
= (comp
<< 29) | (kind
<< 22) | (user
<< 20);
137 priv
->flags5
= (part
<< 16);
139 switch (priv
->base
.target
) {
140 case NV_MEM_TARGET_VM
:
141 priv
->flags0
|= 0x00000000;
143 case NV_MEM_TARGET_VRAM
:
144 priv
->flags0
|= 0x00010000;
146 case NV_MEM_TARGET_PCI
:
147 priv
->flags0
|= 0x00020000;
149 case NV_MEM_TARGET_PCI_NOSNOOP
:
150 priv
->flags0
|= 0x00030000;
156 switch (priv
->base
.access
) {
157 case NV_MEM_ACCESS_VM
:
159 case NV_MEM_ACCESS_RO
:
160 priv
->flags0
|= 0x00040000;
162 case NV_MEM_ACCESS_WO
:
163 case NV_MEM_ACCESS_RW
:
164 priv
->flags0
|= 0x00080000;
170 return dmaeng
->bind(&priv
->base
, nv_object(priv
), (void *)pobject
);
173 static struct nouveau_ofuncs
174 nv50_dmaobj_ofuncs
= {
175 .ctor
= nv50_dmaobj_ctor
,
176 .dtor
= _nvkm_dmaobj_dtor
,
177 .init
= _nvkm_dmaobj_init
,
178 .fini
= _nvkm_dmaobj_fini
,
181 static struct nouveau_oclass
182 nv50_dmaeng_sclass
[] = {
183 { NV_DMA_FROM_MEMORY
, &nv50_dmaobj_ofuncs
},
184 { NV_DMA_TO_MEMORY
, &nv50_dmaobj_ofuncs
},
185 { NV_DMA_IN_MEMORY
, &nv50_dmaobj_ofuncs
},
189 struct nouveau_oclass
*
190 nv50_dmaeng_oclass
= &(struct nvkm_dmaeng_impl
) {
191 .base
.handle
= NV_ENGINE(DMAOBJ
, 0x50),
192 .base
.ofuncs
= &(struct nouveau_ofuncs
) {
193 .ctor
= _nvkm_dmaeng_ctor
,
194 .dtor
= _nvkm_dmaeng_dtor
,
195 .init
= _nvkm_dmaeng_init
,
196 .fini
= _nvkm_dmaeng_fini
,
198 .sclass
= nv50_dmaeng_sclass
,
199 .bind
= nv50_dmaobj_bind
,