1f84aff4eSBen Skeggs /*
2f84aff4eSBen Skeggs * Copyright 2012 Red Hat Inc.
3f84aff4eSBen Skeggs *
4f84aff4eSBen Skeggs * Permission is hereby granted, free of charge, to any person obtaining a
5f84aff4eSBen Skeggs * copy of this software and associated documentation files (the "Software"),
6f84aff4eSBen Skeggs * to deal in the Software without restriction, including without limitation
7f84aff4eSBen Skeggs * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8f84aff4eSBen Skeggs * and/or sell copies of the Software, and to permit persons to whom the
9f84aff4eSBen Skeggs * Software is furnished to do so, subject to the following conditions:
10f84aff4eSBen Skeggs *
11f84aff4eSBen Skeggs * The above copyright notice and this permission notice shall be included in
12f84aff4eSBen Skeggs * all copies or substantial portions of the Software.
13f84aff4eSBen Skeggs *
14f84aff4eSBen Skeggs * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15f84aff4eSBen Skeggs * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16f84aff4eSBen Skeggs * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17f84aff4eSBen Skeggs * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18f84aff4eSBen Skeggs * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19f84aff4eSBen Skeggs * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20f84aff4eSBen Skeggs * OTHER DEALINGS IN THE SOFTWARE.
21f84aff4eSBen Skeggs *
22f84aff4eSBen Skeggs * Authors: Ben Skeggs
23f84aff4eSBen Skeggs */
24f84aff4eSBen Skeggs #include "nv50.h"
25f84aff4eSBen Skeggs
2613de7f46SBen Skeggs #include <core/gpuobj.h>
27f84aff4eSBen Skeggs #include <subdev/bar.h>
2861570911SBen Skeggs #include <engine/disp.h>
2907b9e6ccSBen Skeggs #include <engine/fifo.h>
30f84aff4eSBen Skeggs
3108f7633cSBen Skeggs #include <nvif/class.h>
3207b9e6ccSBen Skeggs #include <nvif/event.h>
33f58ddf95SBen Skeggs
34f84aff4eSBen Skeggs /*******************************************************************************
35f84aff4eSBen Skeggs * software context
36f84aff4eSBen Skeggs ******************************************************************************/
37f84aff4eSBen Skeggs
38f84aff4eSBen Skeggs static int
gf100_sw_chan_vblsem_release(struct nvkm_event_ntfy * notify,u32 bits)391d4dce28SBen Skeggs gf100_sw_chan_vblsem_release(struct nvkm_event_ntfy *notify, u32 bits)
40f84aff4eSBen Skeggs {
41f84aff4eSBen Skeggs struct nv50_sw_chan *chan =
421d4dce28SBen Skeggs container_of(notify, typeof(*chan), vblank.notify[notify->id]);
4307b9e6ccSBen Skeggs struct nvkm_sw *sw = chan->base.sw;
4401d64afcSBen Skeggs struct nvkm_device *device = sw->engine.subdev.device;
4507b9e6ccSBen Skeggs u32 inst = chan->base.fifo->inst->addr >> 12;
46f84aff4eSBen Skeggs
4707b9e6ccSBen Skeggs nvkm_wr32(device, 0x001718, 0x80000000 | inst);
4832932281SBen Skeggs nvkm_bar_flush(device->bar);
4901d64afcSBen Skeggs nvkm_wr32(device, 0x06000c, upper_32_bits(chan->vblank.offset));
5001d64afcSBen Skeggs nvkm_wr32(device, 0x060010, lower_32_bits(chan->vblank.offset));
5101d64afcSBen Skeggs nvkm_wr32(device, 0x060014, chan->vblank.value);
52f84aff4eSBen Skeggs
531d4dce28SBen Skeggs return NVKM_EVENT_DROP;
54f84aff4eSBen Skeggs }
55f84aff4eSBen Skeggs
5661570911SBen Skeggs static bool
gf100_sw_chan_mthd(struct nvkm_sw_chan * base,int subc,u32 mthd,u32 data)5761570911SBen Skeggs gf100_sw_chan_mthd(struct nvkm_sw_chan *base, int subc, u32 mthd, u32 data)
5861570911SBen Skeggs {
5961570911SBen Skeggs struct nv50_sw_chan *chan = nv50_sw_chan(base);
6007b9e6ccSBen Skeggs struct nvkm_engine *engine = chan->base.object.engine;
6161570911SBen Skeggs struct nvkm_device *device = engine->subdev.device;
6261570911SBen Skeggs switch (mthd) {
6361570911SBen Skeggs case 0x0400:
6461570911SBen Skeggs chan->vblank.offset &= 0x00ffffffffULL;
6561570911SBen Skeggs chan->vblank.offset |= (u64)data << 32;
6661570911SBen Skeggs return true;
6761570911SBen Skeggs case 0x0404:
6861570911SBen Skeggs chan->vblank.offset &= 0xff00000000ULL;
6961570911SBen Skeggs chan->vblank.offset |= data;
7061570911SBen Skeggs return true;
7161570911SBen Skeggs case 0x0408:
7261570911SBen Skeggs chan->vblank.value = data;
7361570911SBen Skeggs return true;
7461570911SBen Skeggs case 0x040c:
7561570911SBen Skeggs if (data < device->disp->vblank.index_nr) {
761d4dce28SBen Skeggs nvkm_event_ntfy_allow(&chan->vblank.notify[data]);
7761570911SBen Skeggs return true;
7861570911SBen Skeggs }
7961570911SBen Skeggs break;
8061570911SBen Skeggs case 0x600: /* MP.PM_UNK000 */
8161570911SBen Skeggs nvkm_wr32(device, 0x419e00, data);
8261570911SBen Skeggs return true;
8361570911SBen Skeggs case 0x644: /* MP.TRAP_WARP_ERROR_EN */
8461570911SBen Skeggs if (!(data & ~0x001ffffe)) {
8561570911SBen Skeggs nvkm_wr32(device, 0x419e44, data);
8661570911SBen Skeggs return true;
8761570911SBen Skeggs }
8861570911SBen Skeggs break;
8961570911SBen Skeggs case 0x6ac: /* MP.PM_UNK0AC */
9061570911SBen Skeggs nvkm_wr32(device, 0x419eac, data);
9161570911SBen Skeggs return true;
9261570911SBen Skeggs default:
9361570911SBen Skeggs break;
9461570911SBen Skeggs }
9561570911SBen Skeggs return false;
9661570911SBen Skeggs }
9761570911SBen Skeggs
9861570911SBen Skeggs static const struct nvkm_sw_chan_func
9907b9e6ccSBen Skeggs gf100_sw_chan = {
10007b9e6ccSBen Skeggs .dtor = nv50_sw_chan_dtor,
10161570911SBen Skeggs .mthd = gf100_sw_chan_mthd,
10261570911SBen Skeggs };
10361570911SBen Skeggs
10407b9e6ccSBen Skeggs static int
gf100_sw_chan_new(struct nvkm_sw * sw,struct nvkm_chan * fifoch,const struct nvkm_oclass * oclass,struct nvkm_object ** pobject)105*c546656fSBen Skeggs gf100_sw_chan_new(struct nvkm_sw *sw, struct nvkm_chan *fifoch,
10607b9e6ccSBen Skeggs const struct nvkm_oclass *oclass,
10707b9e6ccSBen Skeggs struct nvkm_object **pobject)
10807b9e6ccSBen Skeggs {
10907b9e6ccSBen Skeggs struct nvkm_disp *disp = sw->engine.subdev.device->disp;
11007b9e6ccSBen Skeggs struct nv50_sw_chan *chan;
11107b9e6ccSBen Skeggs int ret, i;
11207b9e6ccSBen Skeggs
11307b9e6ccSBen Skeggs if (!(chan = kzalloc(sizeof(*chan), GFP_KERNEL)))
11407b9e6ccSBen Skeggs return -ENOMEM;
11507b9e6ccSBen Skeggs *pobject = &chan->base.object;
11607b9e6ccSBen Skeggs
11707b9e6ccSBen Skeggs ret = nvkm_sw_chan_ctor(&gf100_sw_chan, sw, fifoch, oclass,
11807b9e6ccSBen Skeggs &chan->base);
11907b9e6ccSBen Skeggs if (ret)
12007b9e6ccSBen Skeggs return ret;
12107b9e6ccSBen Skeggs
12207b9e6ccSBen Skeggs for (i = 0; disp && i < disp->vblank.index_nr; i++) {
1231d4dce28SBen Skeggs nvkm_event_ntfy_add(&disp->vblank, i, NVKM_DISP_HEAD_EVENT_VBLANK, true,
1241d4dce28SBen Skeggs gf100_sw_chan_vblsem_release, &chan->vblank.notify[i]);
12507b9e6ccSBen Skeggs }
12607b9e6ccSBen Skeggs
12707b9e6ccSBen Skeggs return 0;
12807b9e6ccSBen Skeggs }
129f84aff4eSBen Skeggs
130f84aff4eSBen Skeggs /*******************************************************************************
131f84aff4eSBen Skeggs * software engine/subdev functions
132f84aff4eSBen Skeggs ******************************************************************************/
133f84aff4eSBen Skeggs
13407b9e6ccSBen Skeggs static const struct nvkm_sw_func
1356f41c7c5SBen Skeggs gf100_sw = {
13607b9e6ccSBen Skeggs .chan_new = gf100_sw_chan_new,
13707b9e6ccSBen Skeggs .sclass = {
13808f7633cSBen Skeggs { nvkm_nvsw_new, { -1, -1, NVIF_CLASS_SW_GF100 } },
13907b9e6ccSBen Skeggs {}
14007b9e6ccSBen Skeggs }
14107b9e6ccSBen Skeggs };
14207b9e6ccSBen Skeggs
1436f41c7c5SBen Skeggs int
gf100_sw_new(struct nvkm_device * device,enum nvkm_subdev_type type,int inst,struct nvkm_sw ** psw)1448d6461d8SBen Skeggs gf100_sw_new(struct nvkm_device *device, enum nvkm_subdev_type type, int inst, struct nvkm_sw **psw)
1456f41c7c5SBen Skeggs {
1468d6461d8SBen Skeggs return nvkm_sw_new_(&gf100_sw, device, type, inst, psw);
1476f41c7c5SBen Skeggs }
148