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