blob: bd639de7fea0f13e25fcc7d0c5694ab52f9cdfef [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
Ben Skeggsf86770a2012-08-29 10:54:49 +100025#include <core/device.h>
Ben Skeggs82d23ae2012-10-08 13:39:13 +100026#include <core/gpuobj.h>
27#include <core/class.h>
Ben Skeggsebb945a2012-07-20 08:17:34 +100028
Ben Skeggs82d23ae2012-10-08 13:39:13 +100029#include <subdev/fb.h>
Ben Skeggsebb945a2012-07-20 08:17:34 +100030
Ben Skeggsbc985402014-08-10 04:10:24 +100031#include "priv.h"
Ben Skeggsebb945a2012-07-20 08:17:34 +100032
Ben Skeggsebb945a2012-07-20 08:17:34 +100033static int
Ben Skeggs82d23ae2012-10-08 13:39:13 +100034nvc0_dmaobj_bind(struct nouveau_dmaeng *dmaeng,
35 struct nouveau_object *parent,
36 struct nouveau_dmaobj *dmaobj,
37 struct nouveau_gpuobj **pgpuobj)
38{
Ben Skeggs80fe1552012-10-08 14:34:35 +100039 u32 flags0 = nv_mclass(dmaobj);
40 u32 flags5 = 0x00000000;
41 int ret;
Ben Skeggs82d23ae2012-10-08 13:39:13 +100042
43 if (!nv_iclass(parent, NV_ENGCTX_CLASS)) {
44 switch (nv_mclass(parent->parent)) {
Ben Skeggs370c00f2012-08-14 14:11:49 +100045 case NVA3_DISP_MAST_CLASS:
46 case NVA3_DISP_SYNC_CLASS:
47 case NVA3_DISP_OVLY_CLASS:
48 break;
Ben Skeggs82d23ae2012-10-08 13:39:13 +100049 default:
50 return -EINVAL;
51 }
52 } else
53 return 0;
54
Ben Skeggs80fe1552012-10-08 14:34:35 +100055 if (!(dmaobj->conf0 & NVC0_DMA_CONF0_ENABLE)) {
56 if (dmaobj->target == NV_MEM_TARGET_VM) {
57 dmaobj->conf0 = NVC0_DMA_CONF0_PRIV_VM;
58 dmaobj->conf0 |= NVC0_DMA_CONF0_TYPE_VM;
59 } else {
60 dmaobj->conf0 = NVC0_DMA_CONF0_PRIV_US;
61 dmaobj->conf0 |= NVC0_DMA_CONF0_TYPE_LINEAR;
62 dmaobj->conf0 |= 0x00020000;
63 }
64 }
65
66 flags0 |= (dmaobj->conf0 & NVC0_DMA_CONF0_TYPE) << 22;
67 flags0 |= (dmaobj->conf0 & NVC0_DMA_CONF0_PRIV);
68 flags5 |= (dmaobj->conf0 & NVC0_DMA_CONF0_UNKN);
69
70 switch (dmaobj->target) {
71 case NV_MEM_TARGET_VM:
72 flags0 |= 0x00000000;
73 break;
74 case NV_MEM_TARGET_VRAM:
75 flags0 |= 0x00010000;
76 break;
77 case NV_MEM_TARGET_PCI:
78 flags0 |= 0x00020000;
79 break;
80 case NV_MEM_TARGET_PCI_NOSNOOP:
81 flags0 |= 0x00030000;
82 break;
83 default:
84 return -EINVAL;
85 }
86
87 switch (dmaobj->access) {
88 case NV_MEM_ACCESS_VM:
89 break;
90 case NV_MEM_ACCESS_RO:
91 flags0 |= 0x00040000;
92 break;
93 case NV_MEM_ACCESS_WO:
94 case NV_MEM_ACCESS_RW:
95 flags0 |= 0x00080000;
96 break;
97 }
98
99 ret = nouveau_gpuobj_new(parent, parent, 24, 32, 0, pgpuobj);
100 if (ret == 0) {
101 nv_wo32(*pgpuobj, 0x00, flags0);
102 nv_wo32(*pgpuobj, 0x04, lower_32_bits(dmaobj->limit));
103 nv_wo32(*pgpuobj, 0x08, lower_32_bits(dmaobj->start));
104 nv_wo32(*pgpuobj, 0x0c, upper_32_bits(dmaobj->limit) << 24 |
105 upper_32_bits(dmaobj->start));
106 nv_wo32(*pgpuobj, 0x10, 0x00000000);
107 nv_wo32(*pgpuobj, 0x14, flags5);
108 }
109
Ben Skeggs82d23ae2012-10-08 13:39:13 +1000110 return ret;
111}
112
Ben Skeggsbc985402014-08-10 04:10:24 +1000113struct nouveau_oclass *
114nvc0_dmaeng_oclass = &(struct nvkm_dmaeng_impl) {
115 .base.handle = NV_ENGINE(DMAOBJ, 0xc0),
116 .base.ofuncs = &(struct nouveau_ofuncs) {
117 .ctor = _nvkm_dmaeng_ctor,
118 .dtor = _nvkm_dmaeng_dtor,
119 .init = _nvkm_dmaeng_init,
120 .fini = _nvkm_dmaeng_fini,
Ben Skeggsebb945a2012-07-20 08:17:34 +1000121 },
Ben Skeggsbc985402014-08-10 04:10:24 +1000122 .bind = nvc0_dmaobj_bind,
123}.base;