Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 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 | |
Ben Skeggs | fdb751e | 2014-08-10 04:10:23 +1000 | [diff] [blame] | 25 | #include <nvif/os.h> |
| 26 | #include <nvif/class.h> |
| 27 | |
| 28 | /*XXX*/ |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 29 | #include <core/client.h> |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 30 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 31 | #include "nouveau_drm.h" |
| 32 | #include "nouveau_dma.h" |
| 33 | #include "nouveau_bo.h" |
| 34 | #include "nouveau_chan.h" |
| 35 | #include "nouveau_fence.h" |
| 36 | #include "nouveau_abi16.h" |
| 37 | |
| 38 | MODULE_PARM_DESC(vram_pushbuf, "Create DMA push buffers in VRAM"); |
| 39 | static int nouveau_vram_pushbuf; |
| 40 | module_param_named(vram_pushbuf, nouveau_vram_pushbuf, int, 0400); |
| 41 | |
| 42 | int |
| 43 | nouveau_channel_idle(struct nouveau_channel *chan) |
| 44 | { |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 45 | struct nouveau_cli *cli = (void *)nvif_client(chan->object); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 46 | struct nouveau_fence *fence = NULL; |
| 47 | int ret; |
| 48 | |
Ben Skeggs | 264ce19 | 2013-02-14 13:43:21 +1000 | [diff] [blame] | 49 | ret = nouveau_fence_new(chan, false, &fence); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 50 | if (!ret) { |
| 51 | ret = nouveau_fence_wait(fence, false, false); |
| 52 | nouveau_fence_unref(&fence); |
| 53 | } |
| 54 | |
| 55 | if (ret) |
Ben Skeggs | fa2bade | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 56 | NV_PRINTK(error, cli, "failed to idle channel 0x%08x [%s]\n", |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 57 | chan->object->handle, nvkm_client(&cli->base)->name); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 58 | return ret; |
| 59 | } |
| 60 | |
| 61 | void |
| 62 | nouveau_channel_del(struct nouveau_channel **pchan) |
| 63 | { |
| 64 | struct nouveau_channel *chan = *pchan; |
| 65 | if (chan) { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 66 | if (chan->fence) { |
| 67 | nouveau_channel_idle(chan); |
| 68 | nouveau_fence(chan->drm)->context_del(chan); |
| 69 | } |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 70 | nvif_object_fini(&chan->nvsw); |
| 71 | nvif_object_fini(&chan->gart); |
| 72 | nvif_object_fini(&chan->vram); |
| 73 | nvif_object_ref(NULL, &chan->object); |
| 74 | nvif_object_fini(&chan->push.ctxdma); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 75 | nouveau_bo_vma_del(chan->push.buffer, &chan->push.vma); |
| 76 | nouveau_bo_unmap(chan->push.buffer); |
Marcin Slusarz | 124ea29 | 2012-11-25 23:02:28 +0100 | [diff] [blame] | 77 | if (chan->push.buffer && chan->push.buffer->pin_refcnt) |
| 78 | nouveau_bo_unpin(chan->push.buffer); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 79 | nouveau_bo_ref(NULL, &chan->push.buffer); |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 80 | nvif_device_ref(NULL, &chan->device); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 81 | kfree(chan); |
| 82 | } |
| 83 | *pchan = NULL; |
| 84 | } |
| 85 | |
| 86 | static int |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 87 | nouveau_channel_prep(struct nouveau_drm *drm, struct nvif_device *device, |
| 88 | u32 handle, u32 size, struct nouveau_channel **pchan) |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 89 | { |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 90 | struct nouveau_cli *cli = (void *)nvif_client(&device->base); |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 91 | struct nouveau_instmem *imem = nvkm_instmem(device); |
| 92 | struct nouveau_vmmgr *vmm = nvkm_vmmgr(device); |
| 93 | struct nouveau_fb *pfb = nvkm_fb(device); |
Ben Skeggs | 4acfd70 | 2014-08-10 04:10:24 +1000 | [diff] [blame^] | 94 | struct nv_dma_v0 args = {}; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 95 | struct nouveau_channel *chan; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 96 | u32 target; |
| 97 | int ret; |
| 98 | |
| 99 | chan = *pchan = kzalloc(sizeof(*chan), GFP_KERNEL); |
| 100 | if (!chan) |
| 101 | return -ENOMEM; |
| 102 | |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 103 | nvif_device_ref(device, &chan->device); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 104 | chan->drm = drm; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 105 | |
| 106 | /* allocate memory for dma push buffer */ |
| 107 | target = TTM_PL_FLAG_TT; |
| 108 | if (nouveau_vram_pushbuf) |
| 109 | target = TTM_PL_FLAG_VRAM; |
| 110 | |
| 111 | ret = nouveau_bo_new(drm->dev, size, 0, target, 0, 0, NULL, |
| 112 | &chan->push.buffer); |
| 113 | if (ret == 0) { |
| 114 | ret = nouveau_bo_pin(chan->push.buffer, target); |
| 115 | if (ret == 0) |
| 116 | ret = nouveau_bo_map(chan->push.buffer); |
| 117 | } |
| 118 | |
| 119 | if (ret) { |
| 120 | nouveau_channel_del(pchan); |
| 121 | return ret; |
| 122 | } |
| 123 | |
| 124 | /* create dma object covering the *entire* memory space that the |
| 125 | * pushbuf lives in, this is because the GEM code requires that |
| 126 | * we be able to call out to other (indirect) push buffers |
| 127 | */ |
| 128 | chan->push.vma.offset = chan->push.buffer->bo.offset; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 129 | |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 130 | if (device->info.family >= NV_DEVICE_INFO_V0_TESLA) { |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 131 | ret = nouveau_bo_vma_add(chan->push.buffer, cli->vm, |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 132 | &chan->push.vma); |
| 133 | if (ret) { |
| 134 | nouveau_channel_del(pchan); |
| 135 | return ret; |
| 136 | } |
| 137 | |
Ben Skeggs | 4acfd70 | 2014-08-10 04:10:24 +1000 | [diff] [blame^] | 138 | args.target = NV_DMA_V0_TARGET_VM; |
| 139 | args.access = NV_DMA_V0_ACCESS_VM; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 140 | args.start = 0; |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 141 | args.limit = cli->vm->vmm->limit - 1; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 142 | } else |
| 143 | if (chan->push.buffer->bo.mem.mem_type == TTM_PL_VRAM) { |
Ben Skeggs | dceef5d | 2013-03-04 13:01:21 +1000 | [diff] [blame] | 144 | u64 limit = pfb->ram->size - imem->reserved - 1; |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 145 | if (device->info.family == NV_DEVICE_INFO_V0_TNT) { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 146 | /* nv04 vram pushbuf hack, retarget to its location in |
| 147 | * the framebuffer bar rather than direct vram access.. |
| 148 | * nfi why this exists, it came from the -nv ddx. |
| 149 | */ |
Ben Skeggs | 4acfd70 | 2014-08-10 04:10:24 +1000 | [diff] [blame^] | 150 | args.target = NV_DMA_V0_TARGET_PCI; |
| 151 | args.access = NV_DMA_V0_ACCESS_RDWR; |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 152 | args.start = nv_device_resource_start(nvkm_device(device), 1); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 153 | args.limit = args.start + limit; |
| 154 | } else { |
Ben Skeggs | 4acfd70 | 2014-08-10 04:10:24 +1000 | [diff] [blame^] | 155 | args.target = NV_DMA_V0_TARGET_VRAM; |
| 156 | args.access = NV_DMA_V0_ACCESS_RDWR; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 157 | args.start = 0; |
| 158 | args.limit = limit; |
| 159 | } |
| 160 | } else { |
| 161 | if (chan->drm->agp.stat == ENABLED) { |
Ben Skeggs | 4acfd70 | 2014-08-10 04:10:24 +1000 | [diff] [blame^] | 162 | args.target = NV_DMA_V0_TARGET_AGP; |
| 163 | args.access = NV_DMA_V0_ACCESS_RDWR; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 164 | args.start = chan->drm->agp.base; |
| 165 | args.limit = chan->drm->agp.base + |
| 166 | chan->drm->agp.size - 1; |
| 167 | } else { |
Ben Skeggs | 4acfd70 | 2014-08-10 04:10:24 +1000 | [diff] [blame^] | 168 | args.target = NV_DMA_V0_TARGET_VM; |
| 169 | args.access = NV_DMA_V0_ACCESS_RDWR; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 170 | args.start = 0; |
| 171 | args.limit = vmm->limit - 1; |
| 172 | } |
| 173 | } |
| 174 | |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 175 | ret = nvif_object_init(nvif_object(device), NULL, NVDRM_PUSH | |
Ben Skeggs | 4acfd70 | 2014-08-10 04:10:24 +1000 | [diff] [blame^] | 176 | (handle & 0xffff), NV_DMA_FROM_MEMORY, |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 177 | &args, sizeof(args), &chan->push.ctxdma); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 178 | if (ret) { |
| 179 | nouveau_channel_del(pchan); |
| 180 | return ret; |
| 181 | } |
| 182 | |
| 183 | return 0; |
| 184 | } |
| 185 | |
Marcin Slusarz | 5b8a43a | 2012-08-19 23:00:00 +0200 | [diff] [blame] | 186 | static int |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 187 | nouveau_channel_ind(struct nouveau_drm *drm, struct nvif_device *device, |
| 188 | u32 handle, u32 engine, struct nouveau_channel **pchan) |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 189 | { |
Ben Skeggs | c97f8c9 | 2012-08-19 16:03:00 +1000 | [diff] [blame] | 190 | static const u16 oclasses[] = { NVE0_CHANNEL_IND_CLASS, |
| 191 | NVC0_CHANNEL_IND_CLASS, |
| 192 | NV84_CHANNEL_IND_CLASS, |
| 193 | NV50_CHANNEL_IND_CLASS, |
| 194 | 0 }; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 195 | const u16 *oclass = oclasses; |
Ben Skeggs | dbff2de | 2012-08-06 18:16:37 +1000 | [diff] [blame] | 196 | struct nve0_channel_ind_class args; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 197 | struct nouveau_channel *chan; |
| 198 | int ret; |
| 199 | |
| 200 | /* allocate dma push buffer */ |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 201 | ret = nouveau_channel_prep(drm, device, handle, 0x12000, &chan); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 202 | *pchan = chan; |
| 203 | if (ret) |
| 204 | return ret; |
| 205 | |
| 206 | /* create channel object */ |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 207 | args.pushbuf = chan->push.ctxdma.handle; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 208 | args.ioffset = 0x10000 + chan->push.vma.offset; |
| 209 | args.ilength = 0x02000; |
Ben Skeggs | 4998104 | 2012-08-06 19:38:25 +1000 | [diff] [blame] | 210 | args.engine = engine; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 211 | |
| 212 | do { |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 213 | ret = nvif_object_new(nvif_object(device), handle, *oclass++, |
| 214 | &args, sizeof(args), &chan->object); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 215 | if (ret == 0) |
| 216 | return ret; |
| 217 | } while (*oclass); |
| 218 | |
| 219 | nouveau_channel_del(pchan); |
| 220 | return ret; |
| 221 | } |
| 222 | |
| 223 | static int |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 224 | nouveau_channel_dma(struct nouveau_drm *drm, struct nvif_device *device, |
| 225 | u32 handle, struct nouveau_channel **pchan) |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 226 | { |
Ben Skeggs | c97f8c9 | 2012-08-19 16:03:00 +1000 | [diff] [blame] | 227 | static const u16 oclasses[] = { NV40_CHANNEL_DMA_CLASS, |
| 228 | NV17_CHANNEL_DMA_CLASS, |
| 229 | NV10_CHANNEL_DMA_CLASS, |
| 230 | NV03_CHANNEL_DMA_CLASS, |
| 231 | 0 }; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 232 | const u16 *oclass = oclasses; |
Ben Skeggs | a7c6e75 | 2012-08-14 15:02:29 +1000 | [diff] [blame] | 233 | struct nv03_channel_dma_class args; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 234 | struct nouveau_channel *chan; |
| 235 | int ret; |
| 236 | |
| 237 | /* allocate dma push buffer */ |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 238 | ret = nouveau_channel_prep(drm, device, handle, 0x10000, &chan); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 239 | *pchan = chan; |
| 240 | if (ret) |
| 241 | return ret; |
| 242 | |
| 243 | /* create channel object */ |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 244 | args.pushbuf = chan->push.ctxdma.handle; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 245 | args.offset = chan->push.vma.offset; |
| 246 | |
| 247 | do { |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 248 | ret = nvif_object_new(nvif_object(device), handle, *oclass++, |
| 249 | &args, sizeof(args), &chan->object); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 250 | if (ret == 0) |
| 251 | return ret; |
| 252 | } while (ret && *oclass); |
| 253 | |
| 254 | nouveau_channel_del(pchan); |
| 255 | return ret; |
| 256 | } |
| 257 | |
| 258 | static int |
| 259 | nouveau_channel_init(struct nouveau_channel *chan, u32 vram, u32 gart) |
| 260 | { |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 261 | struct nvif_device *device = chan->device; |
| 262 | struct nouveau_cli *cli = (void *)nvif_client(&device->base); |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 263 | struct nouveau_instmem *imem = nvkm_instmem(device); |
| 264 | struct nouveau_vmmgr *vmm = nvkm_vmmgr(device); |
| 265 | struct nouveau_fb *pfb = nvkm_fb(device); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 266 | struct nouveau_software_chan *swch; |
Ben Skeggs | 4acfd70 | 2014-08-10 04:10:24 +1000 | [diff] [blame^] | 267 | struct nv_dma_v0 args = {}; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 268 | int ret, i; |
| 269 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 270 | /* allocate dma objects to cover all allowed vram, and gart */ |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 271 | if (device->info.family < NV_DEVICE_INFO_V0_FERMI) { |
| 272 | if (device->info.family >= NV_DEVICE_INFO_V0_TESLA) { |
Ben Skeggs | 4acfd70 | 2014-08-10 04:10:24 +1000 | [diff] [blame^] | 273 | args.target = NV_DMA_V0_TARGET_VM; |
| 274 | args.access = NV_DMA_V0_ACCESS_VM; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 275 | args.start = 0; |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 276 | args.limit = cli->vm->vmm->limit - 1; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 277 | } else { |
Ben Skeggs | 4acfd70 | 2014-08-10 04:10:24 +1000 | [diff] [blame^] | 278 | args.target = NV_DMA_V0_TARGET_VRAM; |
| 279 | args.access = NV_DMA_V0_ACCESS_RDWR; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 280 | args.start = 0; |
Ben Skeggs | dceef5d | 2013-03-04 13:01:21 +1000 | [diff] [blame] | 281 | args.limit = pfb->ram->size - imem->reserved - 1; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 282 | } |
| 283 | |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 284 | ret = nvif_object_init(chan->object, NULL, vram, |
Ben Skeggs | 4acfd70 | 2014-08-10 04:10:24 +1000 | [diff] [blame^] | 285 | NV_DMA_IN_MEMORY, &args, |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 286 | sizeof(args), &chan->vram); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 287 | if (ret) |
| 288 | return ret; |
| 289 | |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 290 | if (device->info.family >= NV_DEVICE_INFO_V0_TESLA) { |
Ben Skeggs | 4acfd70 | 2014-08-10 04:10:24 +1000 | [diff] [blame^] | 291 | args.target = NV_DMA_V0_TARGET_VM; |
| 292 | args.access = NV_DMA_V0_ACCESS_VM; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 293 | args.start = 0; |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 294 | args.limit = cli->vm->vmm->limit - 1; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 295 | } else |
| 296 | if (chan->drm->agp.stat == ENABLED) { |
Ben Skeggs | 4acfd70 | 2014-08-10 04:10:24 +1000 | [diff] [blame^] | 297 | args.target = NV_DMA_V0_TARGET_AGP; |
| 298 | args.access = NV_DMA_V0_ACCESS_RDWR; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 299 | args.start = chan->drm->agp.base; |
| 300 | args.limit = chan->drm->agp.base + |
| 301 | chan->drm->agp.size - 1; |
| 302 | } else { |
Ben Skeggs | 4acfd70 | 2014-08-10 04:10:24 +1000 | [diff] [blame^] | 303 | args.target = NV_DMA_V0_TARGET_VM; |
| 304 | args.access = NV_DMA_V0_ACCESS_RDWR; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 305 | args.start = 0; |
| 306 | args.limit = vmm->limit - 1; |
| 307 | } |
| 308 | |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 309 | ret = nvif_object_init(chan->object, NULL, gart, |
Ben Skeggs | 4acfd70 | 2014-08-10 04:10:24 +1000 | [diff] [blame^] | 310 | NV_DMA_IN_MEMORY, &args, |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 311 | sizeof(args), &chan->gart); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 312 | if (ret) |
| 313 | return ret; |
| 314 | } |
| 315 | |
| 316 | /* initialise dma tracking parameters */ |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 317 | switch (chan->object->oclass & 0x00ff) { |
Ben Skeggs | 503b0f1 | 2012-08-14 14:53:51 +1000 | [diff] [blame] | 318 | case 0x006b: |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 319 | case 0x006e: |
| 320 | chan->user_put = 0x40; |
| 321 | chan->user_get = 0x44; |
| 322 | chan->dma.max = (0x10000 / 4) - 2; |
| 323 | break; |
| 324 | default: |
| 325 | chan->user_put = 0x40; |
| 326 | chan->user_get = 0x44; |
| 327 | chan->user_get_hi = 0x60; |
| 328 | chan->dma.ib_base = 0x10000 / 4; |
| 329 | chan->dma.ib_max = (0x02000 / 8) - 1; |
| 330 | chan->dma.ib_put = 0; |
| 331 | chan->dma.ib_free = chan->dma.ib_max - chan->dma.ib_put; |
| 332 | chan->dma.max = chan->dma.ib_base; |
| 333 | break; |
| 334 | } |
| 335 | |
| 336 | chan->dma.put = 0; |
| 337 | chan->dma.cur = chan->dma.put; |
| 338 | chan->dma.free = chan->dma.max - chan->dma.cur; |
| 339 | |
| 340 | ret = RING_SPACE(chan, NOUVEAU_DMA_SKIPS); |
| 341 | if (ret) |
| 342 | return ret; |
| 343 | |
| 344 | for (i = 0; i < NOUVEAU_DMA_SKIPS; i++) |
| 345 | OUT_RING(chan, 0x00000000); |
| 346 | |
Ben Skeggs | 69a6146 | 2013-11-13 10:58:51 +1000 | [diff] [blame] | 347 | /* allocate software object class (used for fences on <= nv05) */ |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 348 | if (device->info.family < NV_DEVICE_INFO_V0_CELSIUS) { |
Ben Skeggs | f45f55c | 2014-08-10 04:10:23 +1000 | [diff] [blame] | 349 | ret = nvif_object_init(chan->object, NULL, 0x006e, 0x006e, |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 350 | NULL, 0, &chan->nvsw); |
Ben Skeggs | 4998104 | 2012-08-06 19:38:25 +1000 | [diff] [blame] | 351 | if (ret) |
| 352 | return ret; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 353 | |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 354 | swch = (void *)nvkm_object(&chan->nvsw)->parent; |
Ben Skeggs | 4998104 | 2012-08-06 19:38:25 +1000 | [diff] [blame] | 355 | swch->flip = nouveau_flip_complete; |
| 356 | swch->flip_data = chan; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 357 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 358 | ret = RING_SPACE(chan, 2); |
| 359 | if (ret) |
| 360 | return ret; |
| 361 | |
| 362 | BEGIN_NV04(chan, NvSubSw, 0x0000, 1); |
Ben Skeggs | f45f55c | 2014-08-10 04:10:23 +1000 | [diff] [blame] | 363 | OUT_RING (chan, chan->nvsw.handle); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 364 | FIRE_RING (chan); |
| 365 | } |
| 366 | |
| 367 | /* initialise synchronisation */ |
| 368 | return nouveau_fence(chan->drm)->context_new(chan); |
| 369 | } |
| 370 | |
| 371 | int |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 372 | nouveau_channel_new(struct nouveau_drm *drm, struct nvif_device *device, |
| 373 | u32 handle, u32 arg0, u32 arg1, |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 374 | struct nouveau_channel **pchan) |
| 375 | { |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 376 | struct nouveau_cli *cli = (void *)nvif_client(&device->base); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 377 | int ret; |
| 378 | |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 379 | ret = nouveau_channel_ind(drm, device, handle, arg0, pchan); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 380 | if (ret) { |
Ben Skeggs | fa2bade | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 381 | NV_PRINTK(debug, cli, "ib channel create, %d\n", ret); |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 382 | ret = nouveau_channel_dma(drm, device, handle, pchan); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 383 | if (ret) { |
Ben Skeggs | fa2bade | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 384 | NV_PRINTK(debug, cli, "dma channel create, %d\n", ret); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 385 | return ret; |
| 386 | } |
| 387 | } |
| 388 | |
Ben Skeggs | 4998104 | 2012-08-06 19:38:25 +1000 | [diff] [blame] | 389 | ret = nouveau_channel_init(*pchan, arg0, arg1); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 390 | if (ret) { |
Ben Skeggs | fa2bade | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 391 | NV_PRINTK(error, cli, "channel failed to initialise, %d\n", ret); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 392 | nouveau_channel_del(pchan); |
| 393 | return ret; |
| 394 | } |
| 395 | |
| 396 | return 0; |
| 397 | } |