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/namedb.h>
29 #include <core/handle.h>
30 #include <core/gpuobj.h>
31 #include <core/event.h>
33 #include <subdev/bar.h>
35 #include <engine/disp.h>
39 /*******************************************************************************
40 * software object classes
41 ******************************************************************************/
44 nv50_software_mthd_dma_vblsem(struct nouveau_object *object, u32 mthd,
47 struct nv50_software_chan *chan = (void *)nv_engctx(object->parent);
48 struct nouveau_fifo_chan *fifo = (void *)nv_object(chan)->parent;
49 struct nouveau_handle *handle;
52 handle = nouveau_namedb_get(nv_namedb(fifo), *(u32 *)args);
56 if (nv_iclass(handle->object, NV_GPUOBJ_CLASS)) {
57 struct nouveau_gpuobj *gpuobj = nv_gpuobj(handle->object);
58 chan->vblank.ctxdma = gpuobj->node->offset >> 4;
61 nouveau_namedb_put(handle);
66 nv50_software_mthd_vblsem_offset(struct nouveau_object *object, u32 mthd,
69 struct nv50_software_chan *chan = (void *)nv_engctx(object->parent);
70 chan->vblank.offset = *(u32 *)args;
75 nv50_software_mthd_vblsem_value(struct nouveau_object *object, u32 mthd,
78 struct nv50_software_chan *chan = (void *)nv_engctx(object->parent);
79 chan->vblank.value = *(u32 *)args;
84 nv50_software_mthd_vblsem_release(struct nouveau_object *object, u32 mthd,
87 struct nv50_software_chan *chan = (void *)nv_engctx(object->parent);
88 u32 head = *(u32 *)args;
89 if (head >= chan->vblank.nr_event)
92 nouveau_event_get(chan->vblank.event[head]);
97 nv50_software_mthd_flip(struct nouveau_object *object, u32 mthd,
100 struct nv50_software_chan *chan = (void *)nv_engctx(object->parent);
102 return chan->base.flip(chan->base.flip_data);
106 static struct nouveau_omthds
107 nv50_software_omthds[] = {
108 { 0x018c, 0x018c, nv50_software_mthd_dma_vblsem },
109 { 0x0400, 0x0400, nv50_software_mthd_vblsem_offset },
110 { 0x0404, 0x0404, nv50_software_mthd_vblsem_value },
111 { 0x0408, 0x0408, nv50_software_mthd_vblsem_release },
112 { 0x0500, 0x0500, nv50_software_mthd_flip },
116 static struct nouveau_oclass
117 nv50_software_sclass[] = {
118 { 0x506e, &nouveau_object_ofuncs, nv50_software_omthds },
122 /*******************************************************************************
124 ******************************************************************************/
127 nv50_software_vblsem_release(void *data, int head)
129 struct nv50_software_chan *chan = data;
130 struct nv50_software_priv *priv = (void *)nv_object(chan)->engine;
131 struct nouveau_bar *bar = nouveau_bar(priv);
133 nv_wr32(priv, 0x001704, chan->vblank.channel);
134 nv_wr32(priv, 0x001710, 0x80000000 | chan->vblank.ctxdma);
137 if (nv_device(priv)->chipset == 0x50) {
138 nv_wr32(priv, 0x001570, chan->vblank.offset);
139 nv_wr32(priv, 0x001574, chan->vblank.value);
141 nv_wr32(priv, 0x060010, chan->vblank.offset);
142 nv_wr32(priv, 0x060014, chan->vblank.value);
145 return NVKM_EVENT_DROP;
149 nv50_software_context_dtor(struct nouveau_object *object)
151 struct nv50_software_chan *chan = (void *)object;
154 if (chan->vblank.event) {
155 for (i = 0; i < chan->vblank.nr_event; i++)
156 nouveau_event_ref(NULL, &chan->vblank.event[i]);
157 kfree(chan->vblank.event);
160 nouveau_software_context_destroy(&chan->base);
164 nv50_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 nouveau_disp *pdisp = nouveau_disp(parent);
170 struct nv50_software_cclass *pclass = (void *)oclass;
171 struct nv50_software_chan *chan;
174 ret = nouveau_software_context_create(parent, engine, oclass, &chan);
175 *pobject = nv_object(chan);
179 chan->vblank.nr_event = pdisp->vblank->index_nr;
180 chan->vblank.event = kzalloc(chan->vblank.nr_event *
181 sizeof(*chan->vblank.event), GFP_KERNEL);
182 if (!chan->vblank.event)
185 for (i = 0; i < chan->vblank.nr_event; i++) {
186 ret = nouveau_event_new(pdisp->vblank, i, pclass->vblank,
187 chan, &chan->vblank.event[i]);
192 chan->vblank.channel = nv_gpuobj(parent->parent)->addr >> 12;
196 static struct nv50_software_cclass
197 nv50_software_cclass = {
198 .base.handle = NV_ENGCTX(SW, 0x50),
199 .base.ofuncs = &(struct nouveau_ofuncs) {
200 .ctor = nv50_software_context_ctor,
201 .dtor = _nouveau_software_context_dtor,
202 .init = _nouveau_software_context_init,
203 .fini = _nouveau_software_context_fini,
205 .vblank = nv50_software_vblsem_release,
208 /*******************************************************************************
209 * software engine/subdev functions
210 ******************************************************************************/
213 nv50_software_ctor(struct nouveau_object *parent, struct nouveau_object *engine,
214 struct nouveau_oclass *oclass, void *data, u32 size,
215 struct nouveau_object **pobject)
217 struct nv50_software_oclass *pclass = (void *)oclass;
218 struct nv50_software_priv *priv;
221 ret = nouveau_software_create(parent, engine, oclass, &priv);
222 *pobject = nv_object(priv);
226 nv_engine(priv)->cclass = pclass->cclass;
227 nv_engine(priv)->sclass = pclass->sclass;
228 nv_subdev(priv)->intr = nv04_software_intr;
232 struct nouveau_oclass *
233 nv50_software_oclass = &(struct nv50_software_oclass) {
234 .base.handle = NV_ENGINE(SW, 0x50),
235 .base.ofuncs = &(struct nouveau_ofuncs) {
236 .ctor = nv50_software_ctor,
237 .dtor = _nouveau_software_dtor,
238 .init = _nouveau_software_init,
239 .fini = _nouveau_software_fini,
241 .cclass = &nv50_software_cclass.base,
242 .sclass = nv50_software_sclass,