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/class.h>
27 #include <core/engctx.h>
28 #include <core/event.h>
30 #include <subdev/bar.h>
32 #include <engine/software.h>
33 #include <engine/disp.h>
35 struct nvc0_software_priv {
36 struct nouveau_software base;
39 struct nvc0_software_chan {
40 struct nouveau_software_chan base;
43 /*******************************************************************************
44 * software object classes
45 ******************************************************************************/
48 nvc0_software_mthd_vblsem_offset(struct nouveau_object *object, u32 mthd,
51 struct nvc0_software_chan *chan = (void *)nv_engctx(object->parent);
52 u64 data = *(u32 *)args;
54 chan->base.vblank.offset &= 0x00ffffffffULL;
55 chan->base.vblank.offset |= data << 32;
57 chan->base.vblank.offset &= 0xff00000000ULL;
58 chan->base.vblank.offset |= data;
64 nvc0_software_mthd_vblsem_value(struct nouveau_object *object, u32 mthd,
67 struct nvc0_software_chan *chan = (void *)nv_engctx(object->parent);
68 chan->base.vblank.value = *(u32 *)args;
73 nvc0_software_mthd_vblsem_release(struct nouveau_object *object, u32 mthd,
76 struct nvc0_software_chan *chan = (void *)nv_engctx(object->parent);
77 struct nouveau_disp *disp = nouveau_disp(object);
78 u32 crtc = *(u32 *)args;
80 if ((nv_device(object)->card_type < NV_E0 && crtc > 1) || crtc > 3)
83 nouveau_event_get(disp->vblank, crtc, &chan->base.vblank.event);
88 nvc0_software_mthd_flip(struct nouveau_object *object, u32 mthd,
91 struct nvc0_software_chan *chan = (void *)nv_engctx(object->parent);
93 return chan->base.flip(chan->base.flip_data);
98 nvc0_software_mthd_mp_control(struct nouveau_object *object, u32 mthd,
101 struct nvc0_software_chan *chan = (void *)nv_engctx(object->parent);
102 struct nvc0_software_priv *priv = (void *)nv_object(chan)->engine;
103 u32 data = *(u32 *)args;
107 nv_wr32(priv, 0x419e00, data); /* MP.PM_UNK000 */
110 if (data & ~0x1ffffe)
112 nv_wr32(priv, 0x419e44, data); /* MP.TRAP_WARP_ERROR_EN */
115 nv_wr32(priv, 0x419eac, data); /* MP.PM_UNK0AC */
123 static struct nouveau_omthds
124 nvc0_software_omthds[] = {
125 { 0x0400, 0x0400, nvc0_software_mthd_vblsem_offset },
126 { 0x0404, 0x0404, nvc0_software_mthd_vblsem_offset },
127 { 0x0408, 0x0408, nvc0_software_mthd_vblsem_value },
128 { 0x040c, 0x040c, nvc0_software_mthd_vblsem_release },
129 { 0x0500, 0x0500, nvc0_software_mthd_flip },
130 { 0x0600, 0x0600, nvc0_software_mthd_mp_control },
131 { 0x0644, 0x0644, nvc0_software_mthd_mp_control },
132 { 0x06ac, 0x06ac, nvc0_software_mthd_mp_control },
136 static struct nouveau_oclass
137 nvc0_software_sclass[] = {
138 { 0x906e, &nouveau_object_ofuncs, nvc0_software_omthds },
142 /*******************************************************************************
144 ******************************************************************************/
147 nvc0_software_vblsem_release(struct nouveau_eventh *event, int head)
149 struct nouveau_software_chan *chan =
150 container_of(event, struct nouveau_software_chan, vblank.event);
151 struct nvc0_software_priv *priv = (void *)nv_object(chan)->engine;
152 struct nouveau_bar *bar = nouveau_bar(priv);
154 nv_wr32(priv, 0x001718, 0x80000000 | chan->vblank.channel);
156 nv_wr32(priv, 0x06000c, upper_32_bits(chan->vblank.offset));
157 nv_wr32(priv, 0x060010, lower_32_bits(chan->vblank.offset));
158 nv_wr32(priv, 0x060014, chan->vblank.value);
160 return NVKM_EVENT_DROP;
164 nvc0_software_context_ctor(struct nouveau_object *parent,
165 struct nouveau_object *engine,
166 struct nouveau_oclass *oclass, void *data, u32 size,
167 struct nouveau_object **pobject)
169 struct nvc0_software_chan *chan;
172 ret = nouveau_software_context_create(parent, engine, oclass, &chan);
173 *pobject = nv_object(chan);
177 chan->base.vblank.channel = nv_gpuobj(parent->parent)->addr >> 12;
178 chan->base.vblank.event.func = nvc0_software_vblsem_release;
182 static struct nouveau_oclass
183 nvc0_software_cclass = {
184 .handle = NV_ENGCTX(SW, 0xc0),
185 .ofuncs = &(struct nouveau_ofuncs) {
186 .ctor = nvc0_software_context_ctor,
187 .dtor = _nouveau_software_context_dtor,
188 .init = _nouveau_software_context_init,
189 .fini = _nouveau_software_context_fini,
193 /*******************************************************************************
194 * software engine/subdev functions
195 ******************************************************************************/
198 nvc0_software_ctor(struct nouveau_object *parent, struct nouveau_object *engine,
199 struct nouveau_oclass *oclass, void *data, u32 size,
200 struct nouveau_object **pobject)
202 struct nvc0_software_priv *priv;
205 ret = nouveau_software_create(parent, engine, oclass, &priv);
206 *pobject = nv_object(priv);
210 nv_engine(priv)->cclass = &nvc0_software_cclass;
211 nv_engine(priv)->sclass = nvc0_software_sclass;
212 nv_subdev(priv)->intr = nv04_software_intr;
216 struct nouveau_oclass
217 nvc0_software_oclass = {
218 .handle = NV_ENGINE(SW, 0xc0),
219 .ofuncs = &(struct nouveau_ofuncs) {
220 .ctor = nvc0_software_ctor,
221 .dtor = _nouveau_software_dtor,
222 .init = _nouveau_software_init,
223 .fini = _nouveau_software_fini,