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> |
Ben Skeggs | 8ed1730 | 2015-11-08 11:28:26 +1000 | [diff] [blame^] | 27 | #include <nvif/cl006b.h> |
| 28 | #include <nvif/cl506f.h> |
| 29 | #include <nvif/cl906f.h> |
| 30 | #include <nvif/cla06f.h> |
Ben Skeggs | f58ddf9 | 2015-08-20 14:54:16 +1000 | [diff] [blame] | 31 | #include <nvif/ioctl.h> |
Ben Skeggs | fdb751e | 2014-08-10 04:10:23 +1000 | [diff] [blame] | 32 | |
| 33 | /*XXX*/ |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 34 | #include <core/client.h> |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 35 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 36 | #include "nouveau_drm.h" |
| 37 | #include "nouveau_dma.h" |
| 38 | #include "nouveau_bo.h" |
| 39 | #include "nouveau_chan.h" |
| 40 | #include "nouveau_fence.h" |
| 41 | #include "nouveau_abi16.h" |
| 42 | |
| 43 | MODULE_PARM_DESC(vram_pushbuf, "Create DMA push buffers in VRAM"); |
Pierre Moreau | 703fa26 | 2014-08-18 22:43:24 +0200 | [diff] [blame] | 44 | int nouveau_vram_pushbuf; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 45 | module_param_named(vram_pushbuf, nouveau_vram_pushbuf, int, 0400); |
| 46 | |
| 47 | int |
| 48 | nouveau_channel_idle(struct nouveau_channel *chan) |
| 49 | { |
Ben Skeggs | fbd58eb | 2015-08-20 14:54:22 +1000 | [diff] [blame] | 50 | if (likely(chan && chan->fence)) { |
| 51 | struct nouveau_cli *cli = (void *)chan->user.client; |
| 52 | struct nouveau_fence *fence = NULL; |
| 53 | int ret; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 54 | |
Ben Skeggs | fbd58eb | 2015-08-20 14:54:22 +1000 | [diff] [blame] | 55 | ret = nouveau_fence_new(chan, false, &fence); |
| 56 | if (!ret) { |
| 57 | ret = nouveau_fence_wait(fence, false, false); |
| 58 | nouveau_fence_unref(&fence); |
| 59 | } |
| 60 | |
| 61 | if (ret) { |
Ben Skeggs | fcf3f91 | 2015-09-04 14:40:32 +1000 | [diff] [blame] | 62 | NV_PRINTK(err, cli, "failed to idle channel %d [%s]\n", |
| 63 | chan->chid, nvxx_client(&cli->base)->name); |
Ben Skeggs | fbd58eb | 2015-08-20 14:54:22 +1000 | [diff] [blame] | 64 | return ret; |
| 65 | } |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 66 | } |
Ben Skeggs | fbd58eb | 2015-08-20 14:54:22 +1000 | [diff] [blame] | 67 | return 0; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | void |
| 71 | nouveau_channel_del(struct nouveau_channel **pchan) |
| 72 | { |
| 73 | struct nouveau_channel *chan = *pchan; |
| 74 | if (chan) { |
Ben Skeggs | fbd58eb | 2015-08-20 14:54:22 +1000 | [diff] [blame] | 75 | if (chan->fence) |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 76 | nouveau_fence(chan->drm)->context_del(chan); |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 77 | nvif_object_fini(&chan->nvsw); |
| 78 | nvif_object_fini(&chan->gart); |
| 79 | nvif_object_fini(&chan->vram); |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 80 | nvif_object_fini(&chan->user); |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 81 | nvif_object_fini(&chan->push.ctxdma); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 82 | nouveau_bo_vma_del(chan->push.buffer, &chan->push.vma); |
| 83 | nouveau_bo_unmap(chan->push.buffer); |
Marcin Slusarz | 124ea29 | 2012-11-25 23:02:28 +0100 | [diff] [blame] | 84 | if (chan->push.buffer && chan->push.buffer->pin_refcnt) |
| 85 | nouveau_bo_unpin(chan->push.buffer); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 86 | nouveau_bo_ref(NULL, &chan->push.buffer); |
| 87 | kfree(chan); |
| 88 | } |
| 89 | *pchan = NULL; |
| 90 | } |
| 91 | |
| 92 | static int |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 93 | nouveau_channel_prep(struct nouveau_drm *drm, struct nvif_device *device, |
Ben Skeggs | fcf3f91 | 2015-09-04 14:40:32 +1000 | [diff] [blame] | 94 | u32 size, struct nouveau_channel **pchan) |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 95 | { |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 96 | struct nouveau_cli *cli = (void *)device->object.client; |
Ben Skeggs | be83cd4 | 2015-01-14 15:36:34 +1000 | [diff] [blame] | 97 | struct nvkm_mmu *mmu = nvxx_mmu(device); |
Ben Skeggs | 4acfd70 | 2014-08-10 04:10:24 +1000 | [diff] [blame] | 98 | struct nv_dma_v0 args = {}; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 99 | struct nouveau_channel *chan; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 100 | u32 target; |
| 101 | int ret; |
| 102 | |
| 103 | chan = *pchan = kzalloc(sizeof(*chan), GFP_KERNEL); |
| 104 | if (!chan) |
| 105 | return -ENOMEM; |
| 106 | |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 107 | chan->device = device; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 108 | chan->drm = drm; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 109 | |
| 110 | /* allocate memory for dma push buffer */ |
Alexandre Courbot | a81349a | 2014-10-27 18:49:18 +0900 | [diff] [blame] | 111 | target = TTM_PL_FLAG_TT | TTM_PL_FLAG_UNCACHED; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 112 | if (nouveau_vram_pushbuf) |
| 113 | target = TTM_PL_FLAG_VRAM; |
| 114 | |
Maarten Lankhorst | bb6178b | 2014-01-09 11:03:15 +0100 | [diff] [blame] | 115 | ret = nouveau_bo_new(drm->dev, size, 0, target, 0, 0, NULL, NULL, |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 116 | &chan->push.buffer); |
| 117 | if (ret == 0) { |
Ben Skeggs | ad76b3f | 2014-11-10 11:24:27 +1000 | [diff] [blame] | 118 | ret = nouveau_bo_pin(chan->push.buffer, target, false); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 119 | if (ret == 0) |
| 120 | ret = nouveau_bo_map(chan->push.buffer); |
| 121 | } |
| 122 | |
| 123 | if (ret) { |
| 124 | nouveau_channel_del(pchan); |
| 125 | return ret; |
| 126 | } |
| 127 | |
| 128 | /* create dma object covering the *entire* memory space that the |
| 129 | * pushbuf lives in, this is because the GEM code requires that |
| 130 | * we be able to call out to other (indirect) push buffers |
| 131 | */ |
| 132 | chan->push.vma.offset = chan->push.buffer->bo.offset; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 133 | |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 134 | if (device->info.family >= NV_DEVICE_INFO_V0_TESLA) { |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 135 | ret = nouveau_bo_vma_add(chan->push.buffer, cli->vm, |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 136 | &chan->push.vma); |
| 137 | if (ret) { |
| 138 | nouveau_channel_del(pchan); |
| 139 | return ret; |
| 140 | } |
| 141 | |
Ben Skeggs | 4acfd70 | 2014-08-10 04:10:24 +1000 | [diff] [blame] | 142 | args.target = NV_DMA_V0_TARGET_VM; |
| 143 | args.access = NV_DMA_V0_ACCESS_VM; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 144 | args.start = 0; |
Ben Skeggs | 5ce3bf3 | 2015-01-14 09:57:36 +1000 | [diff] [blame] | 145 | args.limit = cli->vm->mmu->limit - 1; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 146 | } else |
| 147 | if (chan->push.buffer->bo.mem.mem_type == TTM_PL_VRAM) { |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 148 | if (device->info.family == NV_DEVICE_INFO_V0_TNT) { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 149 | /* nv04 vram pushbuf hack, retarget to its location in |
| 150 | * the framebuffer bar rather than direct vram access.. |
| 151 | * nfi why this exists, it came from the -nv ddx. |
| 152 | */ |
Ben Skeggs | 4acfd70 | 2014-08-10 04:10:24 +1000 | [diff] [blame] | 153 | args.target = NV_DMA_V0_TARGET_PCI; |
| 154 | args.access = NV_DMA_V0_ACCESS_RDWR; |
Ben Skeggs | 7e8820f | 2015-08-20 14:54:23 +1000 | [diff] [blame] | 155 | args.start = nvxx_device(device)->func-> |
| 156 | resource_addr(nvxx_device(device), 1); |
Ben Skeggs | f392ec4 | 2014-08-10 04:10:28 +1000 | [diff] [blame] | 157 | args.limit = args.start + device->info.ram_user - 1; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 158 | } else { |
Ben Skeggs | 4acfd70 | 2014-08-10 04:10:24 +1000 | [diff] [blame] | 159 | args.target = NV_DMA_V0_TARGET_VRAM; |
| 160 | args.access = NV_DMA_V0_ACCESS_RDWR; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 161 | args.start = 0; |
Ben Skeggs | f392ec4 | 2014-08-10 04:10:28 +1000 | [diff] [blame] | 162 | args.limit = device->info.ram_user - 1; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 163 | } |
| 164 | } else { |
Ben Skeggs | 340b0e7c | 2015-08-20 14:54:23 +1000 | [diff] [blame] | 165 | if (chan->drm->agp.bridge) { |
Ben Skeggs | 4acfd70 | 2014-08-10 04:10:24 +1000 | [diff] [blame] | 166 | args.target = NV_DMA_V0_TARGET_AGP; |
| 167 | args.access = NV_DMA_V0_ACCESS_RDWR; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 168 | args.start = chan->drm->agp.base; |
| 169 | args.limit = chan->drm->agp.base + |
| 170 | chan->drm->agp.size - 1; |
| 171 | } else { |
Ben Skeggs | 4acfd70 | 2014-08-10 04:10:24 +1000 | [diff] [blame] | 172 | args.target = NV_DMA_V0_TARGET_VM; |
| 173 | args.access = NV_DMA_V0_ACCESS_RDWR; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 174 | args.start = 0; |
Ben Skeggs | 5ce3bf3 | 2015-01-14 09:57:36 +1000 | [diff] [blame] | 175 | args.limit = mmu->limit - 1; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 176 | } |
| 177 | } |
| 178 | |
Ben Skeggs | fcf3f91 | 2015-09-04 14:40:32 +1000 | [diff] [blame] | 179 | ret = nvif_object_init(&device->object, 0, NV_DMA_FROM_MEMORY, |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 180 | &args, sizeof(args), &chan->push.ctxdma); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 181 | if (ret) { |
| 182 | nouveau_channel_del(pchan); |
| 183 | return ret; |
| 184 | } |
| 185 | |
| 186 | return 0; |
| 187 | } |
| 188 | |
Marcin Slusarz | 5b8a43a | 2012-08-19 23:00:00 +0200 | [diff] [blame] | 189 | static int |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 190 | nouveau_channel_ind(struct nouveau_drm *drm, struct nvif_device *device, |
Ben Skeggs | fcf3f91 | 2015-09-04 14:40:32 +1000 | [diff] [blame] | 191 | u32 engine, struct nouveau_channel **pchan) |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 192 | { |
Ben Skeggs | a1020af | 2015-04-14 11:47:24 +1000 | [diff] [blame] | 193 | static const u16 oclasses[] = { MAXWELL_CHANNEL_GPFIFO_A, |
| 194 | KEPLER_CHANNEL_GPFIFO_A, |
Ben Skeggs | bbf8906 | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 195 | FERMI_CHANNEL_GPFIFO, |
| 196 | G82_CHANNEL_GPFIFO, |
| 197 | NV50_CHANNEL_GPFIFO, |
Ben Skeggs | c97f8c9 | 2012-08-19 16:03:00 +1000 | [diff] [blame] | 198 | 0 }; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 199 | const u16 *oclass = oclasses; |
Ben Skeggs | bbf8906 | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 200 | union { |
| 201 | struct nv50_channel_gpfifo_v0 nv50; |
Ben Skeggs | 159045c | 2015-08-20 14:54:16 +1000 | [diff] [blame] | 202 | struct fermi_channel_gpfifo_v0 fermi; |
Ben Skeggs | bbf8906 | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 203 | struct kepler_channel_gpfifo_a_v0 kepler; |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 204 | } args; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 205 | struct nouveau_channel *chan; |
Ben Skeggs | bbf8906 | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 206 | u32 size; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 207 | int ret; |
| 208 | |
| 209 | /* allocate dma push buffer */ |
Ben Skeggs | fcf3f91 | 2015-09-04 14:40:32 +1000 | [diff] [blame] | 210 | ret = nouveau_channel_prep(drm, device, 0x12000, &chan); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 211 | *pchan = chan; |
| 212 | if (ret) |
| 213 | return ret; |
| 214 | |
| 215 | /* create channel object */ |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 216 | do { |
Ben Skeggs | bbf8906 | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 217 | if (oclass[0] >= KEPLER_CHANNEL_GPFIFO_A) { |
| 218 | args.kepler.version = 0; |
| 219 | args.kepler.engine = engine; |
Ben Skeggs | bbf8906 | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 220 | args.kepler.ilength = 0x02000; |
| 221 | args.kepler.ioffset = 0x10000 + chan->push.vma.offset; |
Ben Skeggs | 159045c | 2015-08-20 14:54:16 +1000 | [diff] [blame] | 222 | args.kepler.vm = 0; |
Ben Skeggs | bbf8906 | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 223 | size = sizeof(args.kepler); |
Ben Skeggs | 159045c | 2015-08-20 14:54:16 +1000 | [diff] [blame] | 224 | } else |
| 225 | if (oclass[0] >= FERMI_CHANNEL_GPFIFO) { |
| 226 | args.fermi.version = 0; |
| 227 | args.fermi.ilength = 0x02000; |
| 228 | args.fermi.ioffset = 0x10000 + chan->push.vma.offset; |
| 229 | args.fermi.vm = 0; |
| 230 | size = sizeof(args.fermi); |
Ben Skeggs | bbf8906 | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 231 | } else { |
| 232 | args.nv50.version = 0; |
Ben Skeggs | bbf8906 | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 233 | args.nv50.ilength = 0x02000; |
| 234 | args.nv50.ioffset = 0x10000 + chan->push.vma.offset; |
Ben Skeggs | 159045c | 2015-08-20 14:54:16 +1000 | [diff] [blame] | 235 | args.nv50.pushbuf = nvif_handle(&chan->push.ctxdma); |
| 236 | args.nv50.vm = 0; |
Ben Skeggs | bbf8906 | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 237 | size = sizeof(args.nv50); |
| 238 | } |
| 239 | |
Ben Skeggs | fcf3f91 | 2015-09-04 14:40:32 +1000 | [diff] [blame] | 240 | ret = nvif_object_init(&device->object, 0, *oclass++, |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 241 | &args, size, &chan->user); |
Ben Skeggs | bbf8906 | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 242 | if (ret == 0) { |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 243 | if (chan->user.oclass >= KEPLER_CHANNEL_GPFIFO_A) |
| 244 | chan->chid = args.kepler.chid; |
Ben Skeggs | bbf8906 | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 245 | else |
Ben Skeggs | 159045c | 2015-08-20 14:54:16 +1000 | [diff] [blame] | 246 | if (chan->user.oclass >= FERMI_CHANNEL_GPFIFO) |
| 247 | chan->chid = args.fermi.chid; |
| 248 | else |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 249 | chan->chid = args.nv50.chid; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 250 | return ret; |
Ben Skeggs | bbf8906 | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 251 | } |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 252 | } while (*oclass); |
| 253 | |
| 254 | nouveau_channel_del(pchan); |
| 255 | return ret; |
| 256 | } |
| 257 | |
| 258 | static int |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 259 | nouveau_channel_dma(struct nouveau_drm *drm, struct nvif_device *device, |
Ben Skeggs | fcf3f91 | 2015-09-04 14:40:32 +1000 | [diff] [blame] | 260 | struct nouveau_channel **pchan) |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 261 | { |
Ben Skeggs | bbf8906 | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 262 | static const u16 oclasses[] = { NV40_CHANNEL_DMA, |
| 263 | NV17_CHANNEL_DMA, |
| 264 | NV10_CHANNEL_DMA, |
| 265 | NV03_CHANNEL_DMA, |
Ben Skeggs | c97f8c9 | 2012-08-19 16:03:00 +1000 | [diff] [blame] | 266 | 0 }; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 267 | const u16 *oclass = oclasses; |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 268 | struct nv03_channel_dma_v0 args; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 269 | struct nouveau_channel *chan; |
| 270 | int ret; |
| 271 | |
| 272 | /* allocate dma push buffer */ |
Ben Skeggs | fcf3f91 | 2015-09-04 14:40:32 +1000 | [diff] [blame] | 273 | ret = nouveau_channel_prep(drm, device, 0x10000, &chan); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 274 | *pchan = chan; |
| 275 | if (ret) |
| 276 | return ret; |
| 277 | |
| 278 | /* create channel object */ |
Ben Skeggs | bbf8906 | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 279 | args.version = 0; |
Ben Skeggs | bf81df9 | 2015-08-20 14:54:16 +1000 | [diff] [blame] | 280 | args.pushbuf = nvif_handle(&chan->push.ctxdma); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 281 | args.offset = chan->push.vma.offset; |
| 282 | |
| 283 | do { |
Ben Skeggs | fcf3f91 | 2015-09-04 14:40:32 +1000 | [diff] [blame] | 284 | ret = nvif_object_init(&device->object, 0, *oclass++, |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 285 | &args, sizeof(args), &chan->user); |
Ben Skeggs | bbf8906 | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 286 | if (ret == 0) { |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 287 | chan->chid = args.chid; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 288 | return ret; |
Ben Skeggs | bbf8906 | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 289 | } |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 290 | } while (ret && *oclass); |
| 291 | |
| 292 | nouveau_channel_del(pchan); |
| 293 | return ret; |
| 294 | } |
| 295 | |
| 296 | static int |
| 297 | nouveau_channel_init(struct nouveau_channel *chan, u32 vram, u32 gart) |
| 298 | { |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 299 | struct nvif_device *device = chan->device; |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 300 | struct nouveau_cli *cli = (void *)chan->user.client; |
Ben Skeggs | be83cd4 | 2015-01-14 15:36:34 +1000 | [diff] [blame] | 301 | struct nvkm_mmu *mmu = nvxx_mmu(device); |
Ben Skeggs | 4acfd70 | 2014-08-10 04:10:24 +1000 | [diff] [blame] | 302 | struct nv_dma_v0 args = {}; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 303 | int ret, i; |
| 304 | |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 305 | nvif_object_map(&chan->user); |
Ben Skeggs | 6c6ae06 | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 306 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 307 | /* allocate dma objects to cover all allowed vram, and gart */ |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 308 | if (device->info.family < NV_DEVICE_INFO_V0_FERMI) { |
| 309 | if (device->info.family >= NV_DEVICE_INFO_V0_TESLA) { |
Ben Skeggs | 4acfd70 | 2014-08-10 04:10:24 +1000 | [diff] [blame] | 310 | args.target = NV_DMA_V0_TARGET_VM; |
| 311 | args.access = NV_DMA_V0_ACCESS_VM; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 312 | args.start = 0; |
Ben Skeggs | 5ce3bf3 | 2015-01-14 09:57:36 +1000 | [diff] [blame] | 313 | args.limit = cli->vm->mmu->limit - 1; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 314 | } else { |
Ben Skeggs | 4acfd70 | 2014-08-10 04:10:24 +1000 | [diff] [blame] | 315 | args.target = NV_DMA_V0_TARGET_VRAM; |
| 316 | args.access = NV_DMA_V0_ACCESS_RDWR; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 317 | args.start = 0; |
Ben Skeggs | f392ec4 | 2014-08-10 04:10:28 +1000 | [diff] [blame] | 318 | args.limit = device->info.ram_user - 1; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 319 | } |
| 320 | |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 321 | ret = nvif_object_init(&chan->user, vram, NV_DMA_IN_MEMORY, |
| 322 | &args, sizeof(args), &chan->vram); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 323 | if (ret) |
| 324 | return ret; |
| 325 | |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 326 | if (device->info.family >= NV_DEVICE_INFO_V0_TESLA) { |
Ben Skeggs | 4acfd70 | 2014-08-10 04:10:24 +1000 | [diff] [blame] | 327 | args.target = NV_DMA_V0_TARGET_VM; |
| 328 | args.access = NV_DMA_V0_ACCESS_VM; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 329 | args.start = 0; |
Ben Skeggs | 5ce3bf3 | 2015-01-14 09:57:36 +1000 | [diff] [blame] | 330 | args.limit = cli->vm->mmu->limit - 1; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 331 | } else |
Ben Skeggs | 340b0e7c | 2015-08-20 14:54:23 +1000 | [diff] [blame] | 332 | if (chan->drm->agp.bridge) { |
Ben Skeggs | 4acfd70 | 2014-08-10 04:10:24 +1000 | [diff] [blame] | 333 | args.target = NV_DMA_V0_TARGET_AGP; |
| 334 | args.access = NV_DMA_V0_ACCESS_RDWR; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 335 | args.start = chan->drm->agp.base; |
| 336 | args.limit = chan->drm->agp.base + |
| 337 | chan->drm->agp.size - 1; |
| 338 | } else { |
Ben Skeggs | 4acfd70 | 2014-08-10 04:10:24 +1000 | [diff] [blame] | 339 | args.target = NV_DMA_V0_TARGET_VM; |
| 340 | args.access = NV_DMA_V0_ACCESS_RDWR; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 341 | args.start = 0; |
Ben Skeggs | 5ce3bf3 | 2015-01-14 09:57:36 +1000 | [diff] [blame] | 342 | args.limit = mmu->limit - 1; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 343 | } |
| 344 | |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 345 | ret = nvif_object_init(&chan->user, gart, NV_DMA_IN_MEMORY, |
| 346 | &args, sizeof(args), &chan->gart); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 347 | if (ret) |
| 348 | return ret; |
| 349 | } |
| 350 | |
| 351 | /* initialise dma tracking parameters */ |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 352 | switch (chan->user.oclass & 0x00ff) { |
Ben Skeggs | 503b0f1 | 2012-08-14 14:53:51 +1000 | [diff] [blame] | 353 | case 0x006b: |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 354 | case 0x006e: |
| 355 | chan->user_put = 0x40; |
| 356 | chan->user_get = 0x44; |
| 357 | chan->dma.max = (0x10000 / 4) - 2; |
| 358 | break; |
| 359 | default: |
| 360 | chan->user_put = 0x40; |
| 361 | chan->user_get = 0x44; |
| 362 | chan->user_get_hi = 0x60; |
| 363 | chan->dma.ib_base = 0x10000 / 4; |
| 364 | chan->dma.ib_max = (0x02000 / 8) - 1; |
| 365 | chan->dma.ib_put = 0; |
| 366 | chan->dma.ib_free = chan->dma.ib_max - chan->dma.ib_put; |
| 367 | chan->dma.max = chan->dma.ib_base; |
| 368 | break; |
| 369 | } |
| 370 | |
| 371 | chan->dma.put = 0; |
| 372 | chan->dma.cur = chan->dma.put; |
| 373 | chan->dma.free = chan->dma.max - chan->dma.cur; |
| 374 | |
| 375 | ret = RING_SPACE(chan, NOUVEAU_DMA_SKIPS); |
| 376 | if (ret) |
| 377 | return ret; |
| 378 | |
| 379 | for (i = 0; i < NOUVEAU_DMA_SKIPS; i++) |
| 380 | OUT_RING(chan, 0x00000000); |
| 381 | |
Ben Skeggs | 69a6146 | 2013-11-13 10:58:51 +1000 | [diff] [blame] | 382 | /* allocate software object class (used for fences on <= nv05) */ |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 383 | if (device->info.family < NV_DEVICE_INFO_V0_CELSIUS) { |
Ben Skeggs | f58ddf9 | 2015-08-20 14:54:16 +1000 | [diff] [blame] | 384 | ret = nvif_object_init(&chan->user, 0x006e, |
Ben Skeggs | 08f7633 | 2015-11-08 10:18:19 +1000 | [diff] [blame] | 385 | NVIF_CLASS_SW_NV04, |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 386 | NULL, 0, &chan->nvsw); |
Ben Skeggs | 4998104 | 2012-08-06 19:38:25 +1000 | [diff] [blame] | 387 | if (ret) |
| 388 | return ret; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 389 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 390 | ret = RING_SPACE(chan, 2); |
| 391 | if (ret) |
| 392 | return ret; |
| 393 | |
| 394 | BEGIN_NV04(chan, NvSubSw, 0x0000, 1); |
Ben Skeggs | f45f55c | 2014-08-10 04:10:23 +1000 | [diff] [blame] | 395 | OUT_RING (chan, chan->nvsw.handle); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 396 | FIRE_RING (chan); |
| 397 | } |
| 398 | |
| 399 | /* initialise synchronisation */ |
Ben Skeggs | 4894f66 | 2014-10-20 15:49:33 +1000 | [diff] [blame] | 400 | return nouveau_fence(chan->drm)->context_new(chan); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | int |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 404 | nouveau_channel_new(struct nouveau_drm *drm, struct nvif_device *device, |
Ben Skeggs | fcf3f91 | 2015-09-04 14:40:32 +1000 | [diff] [blame] | 405 | u32 arg0, u32 arg1, struct nouveau_channel **pchan) |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 406 | { |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 407 | struct nouveau_cli *cli = (void *)device->object.client; |
Ben Skeggs | 67e26e4 | 2014-10-20 15:49:33 +1000 | [diff] [blame] | 408 | bool super; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 409 | int ret; |
| 410 | |
Ben Skeggs | 67e26e4 | 2014-10-20 15:49:33 +1000 | [diff] [blame] | 411 | /* hack until fencenv50 is fixed, and agp access relaxed */ |
| 412 | super = cli->base.super; |
| 413 | cli->base.super = true; |
| 414 | |
Ben Skeggs | fcf3f91 | 2015-09-04 14:40:32 +1000 | [diff] [blame] | 415 | ret = nouveau_channel_ind(drm, device, arg0, pchan); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 416 | if (ret) { |
Ben Skeggs | 9ad97ed | 2015-08-20 14:54:13 +1000 | [diff] [blame] | 417 | NV_PRINTK(dbg, cli, "ib channel create, %d\n", ret); |
Ben Skeggs | fcf3f91 | 2015-09-04 14:40:32 +1000 | [diff] [blame] | 418 | ret = nouveau_channel_dma(drm, device, pchan); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 419 | if (ret) { |
Ben Skeggs | 9ad97ed | 2015-08-20 14:54:13 +1000 | [diff] [blame] | 420 | NV_PRINTK(dbg, cli, "dma channel create, %d\n", ret); |
Ben Skeggs | 67e26e4 | 2014-10-20 15:49:33 +1000 | [diff] [blame] | 421 | goto done; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 422 | } |
| 423 | } |
| 424 | |
Ben Skeggs | 4998104 | 2012-08-06 19:38:25 +1000 | [diff] [blame] | 425 | ret = nouveau_channel_init(*pchan, arg0, arg1); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 426 | if (ret) { |
Ben Skeggs | 9ad97ed | 2015-08-20 14:54:13 +1000 | [diff] [blame] | 427 | NV_PRINTK(err, cli, "channel failed to initialise, %d\n", ret); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 428 | nouveau_channel_del(pchan); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 429 | } |
| 430 | |
Ben Skeggs | 67e26e4 | 2014-10-20 15:49:33 +1000 | [diff] [blame] | 431 | done: |
| 432 | cli->base.super = super; |
| 433 | return ret; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 434 | } |