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