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);
97 static struct nouveau_omthds
98 nvc0_software_omthds[] = {
99 { 0x0400, 0x0400, nvc0_software_mthd_vblsem_offset },
100 { 0x0404, 0x0404, nvc0_software_mthd_vblsem_offset },
101 { 0x0408, 0x0408, nvc0_software_mthd_vblsem_value },
102 { 0x040c, 0x040c, nvc0_software_mthd_vblsem_release },
103 { 0x0500, 0x0500, nvc0_software_mthd_flip },
107 static struct nouveau_oclass
108 nvc0_software_sclass[] = {
109 { 0x906e, &nouveau_object_ofuncs, nvc0_software_omthds },
113 /*******************************************************************************
115 ******************************************************************************/
118 nvc0_software_vblsem_release(struct nouveau_eventh *event, int head)
120 struct nouveau_software_chan *chan =
121 container_of(event, struct nouveau_software_chan, vblank.event);
122 struct nvc0_software_priv *priv = (void *)nv_object(chan)->engine;
123 struct nouveau_bar *bar = nouveau_bar(priv);
125 nv_wr32(priv, 0x001718, 0x80000000 | chan->vblank.channel);
127 nv_wr32(priv, 0x06000c, upper_32_bits(chan->vblank.offset));
128 nv_wr32(priv, 0x060010, lower_32_bits(chan->vblank.offset));
129 nv_wr32(priv, 0x060014, chan->vblank.value);
131 return NVKM_EVENT_DROP;
135 nvc0_software_context_ctor(struct nouveau_object *parent,
136 struct nouveau_object *engine,
137 struct nouveau_oclass *oclass, void *data, u32 size,
138 struct nouveau_object **pobject)
140 struct nvc0_software_chan *chan;
143 ret = nouveau_software_context_create(parent, engine, oclass, &chan);
144 *pobject = nv_object(chan);
148 chan->base.vblank.channel = nv_gpuobj(parent->parent)->addr >> 12;
149 chan->base.vblank.event.func = nvc0_software_vblsem_release;
153 static struct nouveau_oclass
154 nvc0_software_cclass = {
155 .handle = NV_ENGCTX(SW, 0xc0),
156 .ofuncs = &(struct nouveau_ofuncs) {
157 .ctor = nvc0_software_context_ctor,
158 .dtor = _nouveau_software_context_dtor,
159 .init = _nouveau_software_context_init,
160 .fini = _nouveau_software_context_fini,
164 /*******************************************************************************
165 * software engine/subdev functions
166 ******************************************************************************/
169 nvc0_software_ctor(struct nouveau_object *parent, struct nouveau_object *engine,
170 struct nouveau_oclass *oclass, void *data, u32 size,
171 struct nouveau_object **pobject)
173 struct nvc0_software_priv *priv;
176 ret = nouveau_software_create(parent, engine, oclass, &priv);
177 *pobject = nv_object(priv);
181 nv_engine(priv)->cclass = &nvc0_software_cclass;
182 nv_engine(priv)->sclass = nvc0_software_sclass;
183 nv_subdev(priv)->intr = nv04_software_intr;
187 struct nouveau_oclass
188 nvc0_software_oclass = {
189 .handle = NV_ENGINE(SW, 0xc0),
190 .ofuncs = &(struct nouveau_ofuncs) {
191 .ctor = nvc0_software_ctor,
192 .dtor = _nouveau_software_dtor,
193 .init = _nouveau_software_init,
194 .fini = _nouveau_software_fini,