Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +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 | */ |
| 23 | |
Ben Skeggs | a4e610b | 2014-08-10 04:10:23 +1000 | [diff] [blame] | 24 | #include <nvif/client.h> |
| 25 | #include <nvif/driver.h> |
| 26 | #include <nvif/ioctl.h> |
Ben Skeggs | fdb751e | 2014-08-10 04:10:23 +1000 | [diff] [blame] | 27 | #include <nvif/class.h> |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 28 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 29 | #include "nouveau_drm.h" |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 30 | #include "nouveau_dma.h" |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 31 | #include "nouveau_gem.h" |
| 32 | #include "nouveau_chan.h" |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 33 | #include "nouveau_abi16.h" |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 34 | |
| 35 | struct nouveau_abi16 * |
| 36 | nouveau_abi16_get(struct drm_file *file_priv, struct drm_device *dev) |
| 37 | { |
| 38 | struct nouveau_cli *cli = nouveau_cli(file_priv); |
| 39 | mutex_lock(&cli->mutex); |
| 40 | if (!cli->abi16) { |
| 41 | struct nouveau_abi16 *abi16; |
| 42 | cli->abi16 = abi16 = kzalloc(sizeof(*abi16), GFP_KERNEL); |
| 43 | if (cli->abi16) { |
| 44 | INIT_LIST_HEAD(&abi16->channels); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 45 | |
| 46 | /* allocate device object targeting client's default |
| 47 | * device (ie. the one that belongs to the fd it |
| 48 | * opened) |
| 49 | */ |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 50 | if (nvif_device_init(&cli->base.base, NULL, |
Ben Skeggs | a4e610b | 2014-08-10 04:10:23 +1000 | [diff] [blame] | 51 | NOUVEAU_ABI16_DEVICE, NV_DEVICE, |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 52 | &(struct nv_device_class) { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 53 | .device = ~0ULL, |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 54 | }, sizeof(struct nv_device_class), |
| 55 | &abi16->device) == 0) |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 56 | return cli->abi16; |
| 57 | |
| 58 | kfree(cli->abi16); |
| 59 | cli->abi16 = NULL; |
| 60 | } |
| 61 | |
| 62 | mutex_unlock(&cli->mutex); |
| 63 | } |
| 64 | return cli->abi16; |
| 65 | } |
| 66 | |
| 67 | int |
| 68 | nouveau_abi16_put(struct nouveau_abi16 *abi16, int ret) |
| 69 | { |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 70 | struct nouveau_cli *cli = (void *)nvif_client(&abi16->device.base); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 71 | mutex_unlock(&cli->mutex); |
| 72 | return ret; |
| 73 | } |
| 74 | |
| 75 | u16 |
| 76 | nouveau_abi16_swclass(struct nouveau_drm *drm) |
| 77 | { |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 78 | switch (drm->device.info.family) { |
| 79 | case NV_DEVICE_INFO_V0_TNT: |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 80 | return 0x006e; |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 81 | case NV_DEVICE_INFO_V0_CELSIUS: |
| 82 | case NV_DEVICE_INFO_V0_KELVIN: |
| 83 | case NV_DEVICE_INFO_V0_RANKINE: |
| 84 | case NV_DEVICE_INFO_V0_CURIE: |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 85 | return 0x016e; |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 86 | case NV_DEVICE_INFO_V0_TESLA: |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 87 | return 0x506e; |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 88 | case NV_DEVICE_INFO_V0_FERMI: |
| 89 | case NV_DEVICE_INFO_V0_KEPLER: |
| 90 | case NV_DEVICE_INFO_V0_MAXWELL: |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 91 | return 0x906e; |
| 92 | } |
| 93 | |
| 94 | return 0x0000; |
| 95 | } |
| 96 | |
| 97 | static void |
| 98 | nouveau_abi16_ntfy_fini(struct nouveau_abi16_chan *chan, |
| 99 | struct nouveau_abi16_ntfy *ntfy) |
| 100 | { |
| 101 | nouveau_mm_free(&chan->heap, &ntfy->node); |
| 102 | list_del(&ntfy->head); |
| 103 | kfree(ntfy); |
| 104 | } |
| 105 | |
| 106 | static void |
| 107 | nouveau_abi16_chan_fini(struct nouveau_abi16 *abi16, |
| 108 | struct nouveau_abi16_chan *chan) |
| 109 | { |
| 110 | struct nouveau_abi16_ntfy *ntfy, *temp; |
| 111 | |
Marcin Slusarz | 2b77c1c | 2013-03-03 18:58:45 +0100 | [diff] [blame] | 112 | /* wait for all activity to stop before releasing notify object, which |
| 113 | * may be still in use */ |
| 114 | if (chan->chan && chan->ntfy) |
| 115 | nouveau_channel_idle(chan->chan); |
| 116 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 117 | /* cleanup notifier state */ |
| 118 | list_for_each_entry_safe(ntfy, temp, &chan->notifiers, head) { |
| 119 | nouveau_abi16_ntfy_fini(chan, ntfy); |
| 120 | } |
| 121 | |
| 122 | if (chan->ntfy) { |
| 123 | nouveau_bo_vma_del(chan->ntfy, &chan->ntfy_vma); |
Maarten Lankhorst | 198c14a | 2013-06-27 13:38:20 +0200 | [diff] [blame] | 124 | nouveau_bo_unpin(chan->ntfy); |
David Herrmann | 55fb74a | 2013-10-02 10:15:17 +0200 | [diff] [blame] | 125 | drm_gem_object_unreference_unlocked(&chan->ntfy->gem); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | if (chan->heap.block_size) |
| 129 | nouveau_mm_fini(&chan->heap); |
| 130 | |
| 131 | /* destroy channel object, all children will be killed too */ |
| 132 | if (chan->chan) { |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 133 | abi16->handles &= ~(1ULL << (chan->chan->object->handle & 0xffff)); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 134 | nouveau_channel_del(&chan->chan); |
| 135 | } |
| 136 | |
| 137 | list_del(&chan->head); |
| 138 | kfree(chan); |
| 139 | } |
| 140 | |
| 141 | void |
| 142 | nouveau_abi16_fini(struct nouveau_abi16 *abi16) |
| 143 | { |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 144 | struct nouveau_cli *cli = (void *)nvif_client(&abi16->device.base); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 145 | struct nouveau_abi16_chan *chan, *temp; |
| 146 | |
| 147 | /* cleanup channels */ |
| 148 | list_for_each_entry_safe(chan, temp, &abi16->channels, head) { |
| 149 | nouveau_abi16_chan_fini(abi16, chan); |
| 150 | } |
| 151 | |
| 152 | /* destroy the device object */ |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 153 | nvif_device_fini(&abi16->device); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 154 | |
| 155 | kfree(cli->abi16); |
| 156 | cli->abi16 = NULL; |
| 157 | } |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 158 | |
| 159 | int |
| 160 | nouveau_abi16_ioctl_getparam(ABI16_IOCTL_ARGS) |
| 161 | { |
Ben Skeggs | fa2bade | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 162 | struct nouveau_cli *cli = nouveau_cli(file_priv); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 163 | struct nouveau_drm *drm = nouveau_drm(dev); |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 164 | struct nvif_device *device = &drm->device; |
| 165 | struct nouveau_timer *ptimer = nvkm_timer(device); |
| 166 | struct nouveau_graph *graph = nvkm_gr(device); |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 167 | struct drm_nouveau_getparam *getparam = data; |
| 168 | |
| 169 | switch (getparam->param) { |
| 170 | case NOUVEAU_GETPARAM_CHIPSET_ID: |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 171 | getparam->value = device->info.chipset; |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 172 | break; |
| 173 | case NOUVEAU_GETPARAM_PCI_VENDOR: |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 174 | if (nv_device_is_pci(nvkm_device(device))) |
Alexandre Courbot | 420b946 | 2014-02-17 15:17:26 +0900 | [diff] [blame] | 175 | getparam->value = dev->pdev->vendor; |
| 176 | else |
| 177 | getparam->value = 0; |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 178 | break; |
| 179 | case NOUVEAU_GETPARAM_PCI_DEVICE: |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 180 | if (nv_device_is_pci(nvkm_device(device))) |
Alexandre Courbot | 420b946 | 2014-02-17 15:17:26 +0900 | [diff] [blame] | 181 | getparam->value = dev->pdev->device; |
| 182 | else |
| 183 | getparam->value = 0; |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 184 | break; |
| 185 | case NOUVEAU_GETPARAM_BUS_TYPE: |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 186 | if (!nv_device_is_pci(nvkm_device(device))) |
Alexandre Courbot | 420b946 | 2014-02-17 15:17:26 +0900 | [diff] [blame] | 187 | getparam->value = 3; |
| 188 | else |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 189 | if (drm_pci_device_is_agp(dev)) |
| 190 | getparam->value = 0; |
| 191 | else |
| 192 | if (!pci_is_pcie(dev->pdev)) |
| 193 | getparam->value = 1; |
| 194 | else |
| 195 | getparam->value = 2; |
| 196 | break; |
| 197 | case NOUVEAU_GETPARAM_FB_SIZE: |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 198 | getparam->value = drm->gem.vram_available; |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 199 | break; |
| 200 | case NOUVEAU_GETPARAM_AGP_SIZE: |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 201 | getparam->value = drm->gem.gart_available; |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 202 | break; |
| 203 | case NOUVEAU_GETPARAM_VM_VRAM_BASE: |
| 204 | getparam->value = 0; /* deprecated */ |
| 205 | break; |
| 206 | case NOUVEAU_GETPARAM_PTIMER_TIME: |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 207 | getparam->value = ptimer->read(ptimer); |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 208 | break; |
| 209 | case NOUVEAU_GETPARAM_HAS_BO_USAGE: |
| 210 | getparam->value = 1; |
| 211 | break; |
| 212 | case NOUVEAU_GETPARAM_HAS_PAGEFLIP: |
| 213 | getparam->value = 1; |
| 214 | break; |
| 215 | case NOUVEAU_GETPARAM_GRAPH_UNITS: |
Christoph Bumiller | 7e22e71 | 2013-03-27 22:16:54 +0100 | [diff] [blame] | 216 | getparam->value = graph->units ? graph->units(graph) : 0; |
| 217 | break; |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 218 | default: |
Ben Skeggs | fa2bade | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 219 | NV_PRINTK(debug, cli, "unknown parameter %lld\n", getparam->param); |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 220 | return -EINVAL; |
| 221 | } |
| 222 | |
| 223 | return 0; |
| 224 | } |
| 225 | |
| 226 | int |
| 227 | nouveau_abi16_ioctl_setparam(ABI16_IOCTL_ARGS) |
| 228 | { |
| 229 | return -EINVAL; |
| 230 | } |
| 231 | |
| 232 | int |
| 233 | nouveau_abi16_ioctl_channel_alloc(ABI16_IOCTL_ARGS) |
| 234 | { |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 235 | struct drm_nouveau_channel_alloc *init = data; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 236 | struct nouveau_cli *cli = nouveau_cli(file_priv); |
| 237 | struct nouveau_drm *drm = nouveau_drm(dev); |
| 238 | struct nouveau_abi16 *abi16 = nouveau_abi16_get(file_priv, dev); |
| 239 | struct nouveau_abi16_chan *chan; |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 240 | struct nvif_device *device; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 241 | struct nouveau_instmem *imem; |
| 242 | struct nouveau_fb *pfb; |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 243 | int ret; |
| 244 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 245 | if (unlikely(!abi16)) |
| 246 | return -ENOMEM; |
Marcin Slusarz | bf7e438 | 2012-11-11 20:00:09 +0100 | [diff] [blame] | 247 | |
| 248 | if (!drm->channel) |
| 249 | return nouveau_abi16_put(abi16, -ENODEV); |
| 250 | |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 251 | device = &abi16->device; |
| 252 | imem = nvkm_instmem(device); |
| 253 | pfb = nvkm_fb(device); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 254 | |
Ben Skeggs | 4946980 | 2012-11-22 13:43:55 +1000 | [diff] [blame] | 255 | /* hack to allow channel engine type specification on kepler */ |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 256 | if (device->info.family >= NV_DEVICE_INFO_V0_KEPLER) { |
Ben Skeggs | 4946980 | 2012-11-22 13:43:55 +1000 | [diff] [blame] | 257 | if (init->fb_ctxdma_handle != ~0) |
| 258 | init->fb_ctxdma_handle = NVE0_CHANNEL_IND_ENGINE_GR; |
| 259 | else |
| 260 | init->fb_ctxdma_handle = init->tt_ctxdma_handle; |
| 261 | |
| 262 | /* allow flips to be executed if this is a graphics channel */ |
| 263 | init->tt_ctxdma_handle = 0; |
| 264 | if (init->fb_ctxdma_handle == NVE0_CHANNEL_IND_ENGINE_GR) |
| 265 | init->tt_ctxdma_handle = 1; |
| 266 | } |
| 267 | |
| 268 | if (init->fb_ctxdma_handle == ~0 || init->tt_ctxdma_handle == ~0) |
| 269 | return nouveau_abi16_put(abi16, -EINVAL); |
| 270 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 271 | /* allocate "abi16 channel" data and make up a handle for it */ |
Ilia Mirkin | 73970c4 | 2014-02-09 15:51:24 -0500 | [diff] [blame] | 272 | init->channel = __ffs64(~abi16->handles); |
| 273 | if (~abi16->handles == 0) |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 274 | return nouveau_abi16_put(abi16, -ENOSPC); |
| 275 | |
| 276 | chan = kzalloc(sizeof(*chan), GFP_KERNEL); |
| 277 | if (!chan) |
| 278 | return nouveau_abi16_put(abi16, -ENOMEM); |
| 279 | |
| 280 | INIT_LIST_HEAD(&chan->notifiers); |
| 281 | list_add(&chan->head, &abi16->channels); |
Ilia Mirkin | ef98c1f | 2014-02-09 15:51:25 -0500 | [diff] [blame] | 282 | abi16->handles |= (1ULL << init->channel); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 283 | |
| 284 | /* create channel object and initialise dma and fence management */ |
Ben Skeggs | a4e610b | 2014-08-10 04:10:23 +1000 | [diff] [blame] | 285 | ret = nouveau_channel_new(drm, device, |
| 286 | NOUVEAU_ABI16_CHAN(init->channel), |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 287 | init->fb_ctxdma_handle, |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 288 | init->tt_ctxdma_handle, &chan->chan); |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 289 | if (ret) |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 290 | goto done; |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 291 | |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 292 | if (device->info.family >= NV_DEVICE_INFO_V0_TESLA) |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 293 | init->pushbuf_domains = NOUVEAU_GEM_DOMAIN_VRAM | |
| 294 | NOUVEAU_GEM_DOMAIN_GART; |
| 295 | else |
| 296 | if (chan->chan->push.buffer->bo.mem.mem_type == TTM_PL_VRAM) |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 297 | init->pushbuf_domains = NOUVEAU_GEM_DOMAIN_VRAM; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 298 | else |
| 299 | init->pushbuf_domains = NOUVEAU_GEM_DOMAIN_GART; |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 300 | |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 301 | if (device->info.family < NV_DEVICE_INFO_V0_CELSIUS) { |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 302 | init->subchan[0].handle = 0x00000000; |
| 303 | init->subchan[0].grclass = 0x0000; |
Ben Skeggs | f45f55c4 | 2014-08-10 04:10:23 +1000 | [diff] [blame] | 304 | init->subchan[1].handle = chan->chan->nvsw.handle; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 305 | init->subchan[1].grclass = 0x506e; |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 306 | init->nr_subchan = 2; |
| 307 | } |
| 308 | |
| 309 | /* Named memory object area */ |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 310 | ret = nouveau_gem_new(dev, PAGE_SIZE, 0, NOUVEAU_GEM_DOMAIN_GART, |
| 311 | 0, 0, &chan->ntfy); |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 312 | if (ret == 0) |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 313 | ret = nouveau_bo_pin(chan->ntfy, TTM_PL_FLAG_TT); |
| 314 | if (ret) |
| 315 | goto done; |
| 316 | |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 317 | if (device->info.family >= NV_DEVICE_INFO_V0_TESLA) { |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 318 | ret = nouveau_bo_vma_add(chan->ntfy, cli->vm, |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 319 | &chan->ntfy_vma); |
| 320 | if (ret) |
| 321 | goto done; |
| 322 | } |
| 323 | |
David Herrmann | 55fb74a | 2013-10-02 10:15:17 +0200 | [diff] [blame] | 324 | ret = drm_gem_handle_create(file_priv, &chan->ntfy->gem, |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 325 | &init->notifier_handle); |
| 326 | if (ret) |
| 327 | goto done; |
| 328 | |
| 329 | ret = nouveau_mm_init(&chan->heap, 0, PAGE_SIZE, 1); |
| 330 | done: |
| 331 | if (ret) |
| 332 | nouveau_abi16_chan_fini(abi16, chan); |
| 333 | return nouveau_abi16_put(abi16, ret); |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 334 | } |
| 335 | |
Ben Skeggs | a4e610b | 2014-08-10 04:10:23 +1000 | [diff] [blame] | 336 | static struct nouveau_abi16_chan * |
| 337 | nouveau_abi16_chan(struct nouveau_abi16 *abi16, int channel) |
| 338 | { |
| 339 | struct nouveau_abi16_chan *chan; |
| 340 | |
| 341 | list_for_each_entry(chan, &abi16->channels, head) { |
| 342 | if (chan->chan->object->handle == NOUVEAU_ABI16_CHAN(channel)) |
| 343 | return chan; |
| 344 | } |
| 345 | |
| 346 | return NULL; |
| 347 | } |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 348 | |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 349 | int |
| 350 | nouveau_abi16_ioctl_channel_free(ABI16_IOCTL_ARGS) |
| 351 | { |
| 352 | struct drm_nouveau_channel_free *req = data; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 353 | struct nouveau_abi16 *abi16 = nouveau_abi16_get(file_priv, dev); |
| 354 | struct nouveau_abi16_chan *chan; |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 355 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 356 | if (unlikely(!abi16)) |
| 357 | return -ENOMEM; |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 358 | |
Ben Skeggs | a4e610b | 2014-08-10 04:10:23 +1000 | [diff] [blame] | 359 | chan = nouveau_abi16_chan(abi16, req->channel); |
| 360 | if (!chan) |
| 361 | return nouveau_abi16_put(abi16, -ENOENT); |
| 362 | nouveau_abi16_chan_fini(abi16, chan); |
| 363 | return nouveau_abi16_put(abi16, 0); |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | int |
| 367 | nouveau_abi16_ioctl_grobj_alloc(ABI16_IOCTL_ARGS) |
| 368 | { |
| 369 | struct drm_nouveau_grobj_alloc *init = data; |
Ben Skeggs | a4e610b | 2014-08-10 04:10:23 +1000 | [diff] [blame] | 370 | struct { |
| 371 | struct nvif_ioctl_v0 ioctl; |
| 372 | struct nvif_ioctl_new_v0 new; |
| 373 | } args = { |
| 374 | .ioctl.owner = NVIF_IOCTL_V0_OWNER_ANY, |
| 375 | .ioctl.type = NVIF_IOCTL_V0_NEW, |
| 376 | .ioctl.path_nr = 3, |
| 377 | .ioctl.path[2] = NOUVEAU_ABI16_CLIENT, |
| 378 | .ioctl.path[1] = NOUVEAU_ABI16_DEVICE, |
| 379 | .ioctl.path[0] = NOUVEAU_ABI16_CHAN(init->channel), |
| 380 | .new.route = NVDRM_OBJECT_ABI16, |
| 381 | .new.handle = init->handle, |
| 382 | .new.oclass = init->class, |
| 383 | }; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 384 | struct nouveau_abi16 *abi16 = nouveau_abi16_get(file_priv, dev); |
| 385 | struct nouveau_drm *drm = nouveau_drm(dev); |
Ben Skeggs | a4e610b | 2014-08-10 04:10:23 +1000 | [diff] [blame] | 386 | struct nvif_client *client; |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 387 | int ret; |
| 388 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 389 | if (unlikely(!abi16)) |
| 390 | return -ENOMEM; |
| 391 | |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 392 | if (init->handle == ~0) |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 393 | return nouveau_abi16_put(abi16, -EINVAL); |
Ben Skeggs | a4e610b | 2014-08-10 04:10:23 +1000 | [diff] [blame] | 394 | client = nvif_client(nvif_object(&abi16->device)); |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 395 | |
| 396 | /* compatibility with userspace that assumes 506e for all chipsets */ |
| 397 | if (init->class == 0x506e) { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 398 | init->class = nouveau_abi16_swclass(drm); |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 399 | if (init->class == 0x906e) |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 400 | return nouveau_abi16_put(abi16, 0); |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 401 | } |
| 402 | |
Ben Skeggs | a4e610b | 2014-08-10 04:10:23 +1000 | [diff] [blame] | 403 | ret = nvif_client_ioctl(client, &args, sizeof(args)); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 404 | return nouveau_abi16_put(abi16, ret); |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | int |
| 408 | nouveau_abi16_ioctl_notifierobj_alloc(ABI16_IOCTL_ARGS) |
| 409 | { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 410 | struct drm_nouveau_notifierobj_alloc *info = data; |
Ben Skeggs | 3bdda04 | 2014-08-10 04:10:23 +1000 | [diff] [blame^] | 411 | struct { |
| 412 | struct nvif_ioctl_v0 ioctl; |
| 413 | struct nvif_ioctl_new_v0 new; |
| 414 | struct nv_dma_class ctxdma; |
| 415 | } args = { |
| 416 | .ioctl.owner = NVIF_IOCTL_V0_OWNER_ANY, |
| 417 | .ioctl.type = NVIF_IOCTL_V0_NEW, |
| 418 | .ioctl.path_nr = 3, |
| 419 | .ioctl.path[2] = NOUVEAU_ABI16_CLIENT, |
| 420 | .ioctl.path[1] = NOUVEAU_ABI16_DEVICE, |
| 421 | .ioctl.path[0] = NOUVEAU_ABI16_CHAN(info->channel), |
| 422 | .new.route = NVDRM_OBJECT_ABI16, |
| 423 | .new.handle = info->handle, |
| 424 | .new.oclass = NV_DMA_IN_MEMORY_CLASS, |
| 425 | }; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 426 | struct nouveau_drm *drm = nouveau_drm(dev); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 427 | struct nouveau_abi16 *abi16 = nouveau_abi16_get(file_priv, dev); |
Ben Skeggs | a4e610b | 2014-08-10 04:10:23 +1000 | [diff] [blame] | 428 | struct nouveau_abi16_chan *chan; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 429 | struct nouveau_abi16_ntfy *ntfy; |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 430 | struct nvif_device *device = &abi16->device; |
Ben Skeggs | 3bdda04 | 2014-08-10 04:10:23 +1000 | [diff] [blame^] | 431 | struct nvif_client *client; |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 432 | int ret; |
| 433 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 434 | if (unlikely(!abi16)) |
| 435 | return -ENOMEM; |
| 436 | |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 437 | /* completely unnecessary for these chipsets... */ |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 438 | if (unlikely(device->info.family >= NV_DEVICE_INFO_V0_FERMI)) |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 439 | return nouveau_abi16_put(abi16, -EINVAL); |
Ben Skeggs | 3bdda04 | 2014-08-10 04:10:23 +1000 | [diff] [blame^] | 440 | client = nvif_client(nvif_object(&abi16->device)); |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 441 | |
Ben Skeggs | a4e610b | 2014-08-10 04:10:23 +1000 | [diff] [blame] | 442 | chan = nouveau_abi16_chan(abi16, info->channel); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 443 | if (!chan) |
| 444 | return nouveau_abi16_put(abi16, -ENOENT); |
| 445 | |
| 446 | ntfy = kzalloc(sizeof(*ntfy), GFP_KERNEL); |
| 447 | if (!ntfy) |
| 448 | return nouveau_abi16_put(abi16, -ENOMEM); |
| 449 | |
| 450 | list_add(&ntfy->head, &chan->notifiers); |
| 451 | ntfy->handle = info->handle; |
| 452 | |
| 453 | ret = nouveau_mm_head(&chan->heap, 1, info->size, info->size, 1, |
| 454 | &ntfy->node); |
| 455 | if (ret) |
| 456 | goto done; |
| 457 | |
Ben Skeggs | 3bdda04 | 2014-08-10 04:10:23 +1000 | [diff] [blame^] | 458 | args.ctxdma.start = ntfy->node->offset; |
| 459 | args.ctxdma.limit = ntfy->node->offset + ntfy->node->length - 1; |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 460 | if (device->info.family >= NV_DEVICE_INFO_V0_TESLA) { |
Ben Skeggs | 3bdda04 | 2014-08-10 04:10:23 +1000 | [diff] [blame^] | 461 | args.ctxdma.flags = NV_DMA_TARGET_VM | NV_DMA_ACCESS_VM; |
| 462 | args.ctxdma.start += chan->ntfy_vma.offset; |
| 463 | args.ctxdma.limit += chan->ntfy_vma.offset; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 464 | } else |
| 465 | if (drm->agp.stat == ENABLED) { |
Ben Skeggs | 3bdda04 | 2014-08-10 04:10:23 +1000 | [diff] [blame^] | 466 | args.ctxdma.flags = NV_DMA_TARGET_AGP | NV_DMA_ACCESS_RDWR; |
| 467 | args.ctxdma.start += drm->agp.base + chan->ntfy->bo.offset; |
| 468 | args.ctxdma.limit += drm->agp.base + chan->ntfy->bo.offset; |
| 469 | client->super = true; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 470 | } else { |
Ben Skeggs | 3bdda04 | 2014-08-10 04:10:23 +1000 | [diff] [blame^] | 471 | args.ctxdma.flags = NV_DMA_TARGET_VM | NV_DMA_ACCESS_RDWR; |
| 472 | args.ctxdma.start += chan->ntfy->bo.offset; |
| 473 | args.ctxdma.limit += chan->ntfy->bo.offset; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 474 | } |
| 475 | |
Ben Skeggs | 3bdda04 | 2014-08-10 04:10:23 +1000 | [diff] [blame^] | 476 | ret = nvif_client_ioctl(client, &args, sizeof(args)); |
| 477 | client->super = false; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 478 | if (ret) |
| 479 | goto done; |
| 480 | |
Bob Gleitsmann | c1ccaa6 | 2014-01-06 08:59:07 +1000 | [diff] [blame] | 481 | info->offset = ntfy->node->offset; |
| 482 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 483 | done: |
| 484 | if (ret) |
| 485 | nouveau_abi16_ntfy_fini(chan, ntfy); |
| 486 | return nouveau_abi16_put(abi16, ret); |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | int |
| 490 | nouveau_abi16_ioctl_gpuobj_free(ABI16_IOCTL_ARGS) |
| 491 | { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 492 | struct drm_nouveau_gpuobj_free *fini = data; |
| 493 | struct nouveau_abi16 *abi16 = nouveau_abi16_get(file_priv, dev); |
Ben Skeggs | a4e610b | 2014-08-10 04:10:23 +1000 | [diff] [blame] | 494 | struct nouveau_abi16_chan *chan; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 495 | struct nouveau_abi16_ntfy *ntfy; |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 496 | int ret; |
| 497 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 498 | if (unlikely(!abi16)) |
| 499 | return -ENOMEM; |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 500 | |
Ben Skeggs | a4e610b | 2014-08-10 04:10:23 +1000 | [diff] [blame] | 501 | chan = nouveau_abi16_chan(abi16, fini->channel); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 502 | if (!chan) |
| 503 | return nouveau_abi16_put(abi16, -ENOENT); |
| 504 | |
| 505 | /* synchronize with the user channel and destroy the gpu object */ |
| 506 | nouveau_channel_idle(chan->chan); |
| 507 | |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 508 | /*XXX*/ |
| 509 | ret = nouveau_object_del(nv_object(nvkm_client(&abi16->device.base)), |
| 510 | chan->chan->object->handle, fini->handle); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 511 | if (ret) |
| 512 | return nouveau_abi16_put(abi16, ret); |
| 513 | |
| 514 | /* cleanup extra state if this object was a notifier */ |
| 515 | list_for_each_entry(ntfy, &chan->notifiers, head) { |
| 516 | if (ntfy->handle == fini->handle) { |
| 517 | nouveau_mm_free(&chan->heap, &ntfy->node); |
| 518 | list_del(&ntfy->head); |
| 519 | break; |
| 520 | } |
| 521 | } |
| 522 | |
| 523 | return nouveau_abi16_put(abi16, 0); |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 524 | } |