1 /* 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 #include "nv50.h" 25 26 #include <core/gpuobj.h> 27 #include <core/handle.h> 28 #include <engine/disp.h> 29 #include <engine/fifo/chan.h> 30 #include <subdev/bar.h> 31 32 #include <nvif/event.h> 33 #include <nvif/ioctl.h> 34 35 /******************************************************************************* 36 * software context 37 ******************************************************************************/ 38 39 static int 40 nv50_sw_chan_vblsem_release(struct nvkm_notify *notify) 41 { 42 struct nv50_sw_chan *chan = 43 container_of(notify, typeof(*chan), vblank.notify[notify->index]); 44 struct nvkm_sw *sw = chan->base.sw; 45 struct nvkm_device *device = sw->engine.subdev.device; 46 47 nvkm_wr32(device, 0x001704, chan->base.fifo->inst->addr >> 12); 48 nvkm_wr32(device, 0x001710, 0x80000000 | chan->vblank.ctxdma); 49 nvkm_bar_flush(device->bar); 50 51 if (device->chipset == 0x50) { 52 nvkm_wr32(device, 0x001570, chan->vblank.offset); 53 nvkm_wr32(device, 0x001574, chan->vblank.value); 54 } else { 55 nvkm_wr32(device, 0x060010, chan->vblank.offset); 56 nvkm_wr32(device, 0x060014, chan->vblank.value); 57 } 58 59 return NVKM_NOTIFY_DROP; 60 } 61 62 static bool 63 nv50_sw_chan_mthd(struct nvkm_sw_chan *base, int subc, u32 mthd, u32 data) 64 { 65 struct nv50_sw_chan *chan = nv50_sw_chan(base); 66 struct nvkm_engine *engine = chan->base.object.engine; 67 struct nvkm_device *device = engine->subdev.device; 68 switch (mthd) { 69 case 0x018c: chan->vblank.ctxdma = data; return true; 70 case 0x0400: chan->vblank.offset = data; return true; 71 case 0x0404: chan->vblank.value = data; return true; 72 case 0x0408: 73 if (data < device->disp->vblank.index_nr) { 74 nvkm_notify_get(&chan->vblank.notify[data]); 75 return true; 76 } 77 break; 78 default: 79 break; 80 } 81 return false; 82 } 83 84 void * 85 nv50_sw_chan_dtor(struct nvkm_sw_chan *base) 86 { 87 struct nv50_sw_chan *chan = nv50_sw_chan(base); 88 int i; 89 for (i = 0; i < ARRAY_SIZE(chan->vblank.notify); i++) 90 nvkm_notify_fini(&chan->vblank.notify[i]); 91 return chan; 92 } 93 94 static const struct nvkm_sw_chan_func 95 nv50_sw_chan = { 96 .dtor = nv50_sw_chan_dtor, 97 .mthd = nv50_sw_chan_mthd, 98 }; 99 100 static int 101 nv50_sw_chan_new(struct nvkm_sw *sw, struct nvkm_fifo_chan *fifoch, 102 const struct nvkm_oclass *oclass, struct nvkm_object **pobject) 103 { 104 struct nvkm_disp *disp = sw->engine.subdev.device->disp; 105 struct nv50_sw_chan *chan; 106 int ret, i; 107 108 if (!(chan = kzalloc(sizeof(*chan), GFP_KERNEL))) 109 return -ENOMEM; 110 *pobject = &chan->base.object; 111 112 ret = nvkm_sw_chan_ctor(&nv50_sw_chan, sw, fifoch, oclass, &chan->base); 113 if (ret) 114 return ret; 115 116 for (i = 0; disp && i < disp->vblank.index_nr; i++) { 117 ret = nvkm_notify_init(NULL, &disp->vblank, 118 nv50_sw_chan_vblsem_release, false, 119 &(struct nvif_notify_head_req_v0) { 120 .head = i, 121 }, 122 sizeof(struct nvif_notify_head_req_v0), 123 sizeof(struct nvif_notify_head_rep_v0), 124 &chan->vblank.notify[i]); 125 if (ret) 126 return ret; 127 } 128 129 return 0; 130 } 131 132 /******************************************************************************* 133 * software engine/subdev functions 134 ******************************************************************************/ 135 136 static const struct nvkm_sw_func 137 nv50_sw = { 138 .chan_new = nv50_sw_chan_new, 139 .sclass = { 140 { nvkm_nvsw_new, { -1, -1, NVIF_IOCTL_NEW_V0_SW_NV50 } }, 141 {} 142 } 143 }; 144 145 int 146 nv50_sw_new(struct nvkm_device *device, int index, struct nvkm_sw **psw) 147 { 148 return nvkm_sw_new_(&nv50_sw, device, index, psw); 149 } 150